我有一个名为 User 的模型,但 Sequelize 会在我尝试保存在数据库中时查找表 USERS。有谁知道如何将 Sequelize 设置为使用单数表名?谢谢。
最佳答案
docs声明您可以使用属性 freezeTableName
。
请看一下这个例子:
var Bar = sequelize.define('Bar', { /* bla */ }, {
// don't add the timestamp attributes (updatedAt, createdAt)
timestamps: false,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of tablenames; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: true,
// define the table's name
tableName: 'my_very_custom_table_name'
})
关于mysql - 如何使 Sequelize 使用单数表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21114499/