gpt4 book ai didi

mysql - 如何使 Sequelize 使用单数表名

转载 作者:IT老高 更新时间:2023-10-28 12:51:19 26 4
gpt4 key购买 nike

我有一个名为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com