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

标签 mysql sql node.js sequelize.js

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

相关文章:

MySQL:跨多对多和一对多(以及其他东西)进行计数

mysql - 将值插入空列

mysql - nagios如何通过shell脚本监控远程主机?

javascript - 排除 Express.js 路由中的单词列表

php - 选择条件 SQL 语句

mysql - 3 个表之间的 HQL 多对多

node.js - 从命令行停止 node.js 程序

javascript - FailureFlash 与 Passportjs 和 Express

mysql - 从类表继承确定类型

sql - 2020-02-29减去一年导致错误ORA-01839 : date not valid for month specified