Mysql sync({force:false})创建不需要的表
我正在玩我在“Medium”上找到的代码,并更改了模型中表的名称,表单:Mysql sync({force:false})创建不需要的表,mysql,node.js,sequelize.js,Mysql,Node.js,Sequelize.js,我正在玩我在“Medium”上找到的代码,并更改了模型中表的名称,表单: const connection = require ('../connection'); const { Sequelize } = connection; const User = connection.define('user', { id: { type: connection.Sequelize.UUID, defaultValue: connection.Sequeli
const connection = require ('../connection');
const { Sequelize } = connection;
const User = connection.define('user', {
id: {
type: connection.Sequelize.UUID,
defaultValue: connection.Sequelize.UUIDV4,
primaryKey: true
},
name: Sequelize.STRING,
password: Sequelize.STRING
});
module.exports = User;
致:
我还更改了数据库中表的名称
然后我决定回到原来的名字。
但是,从那时起,每次运行整个代码时,我的数据库都会显示两个表:
+--------------------+
| Tables_in_database |
+--------------------+
| user |
| users |
+--------------------+
请注意,我已将表名从“user”更改为“Users”,而不是“Users”,但创建的表是“Users”
尽管如此,我还是删除了表“users”,但是如果我运行代码,它将被重新创建
我到处都找过了,似乎没有提到“用户”表或模型。
唯一阻止创建表的是从index.js中删除以下行:
connection.sync({force: false});
为什么会发生这种情况?我如何防止创建表,甚至在connection.sync仍然存在的情况下?我认为这可以帮助您:
有关更多详细信息:了解“connection.sync”日志可能会很有用:执行默认值:创建表如果不存在用户id CHAR36 BINARY、名称VARCHAR255、密码VARCHAR255、createdAt DATETIME NOT NULL、updatedAt DATETIME NOT NULL、主键id ENGINE=InnoDB;执行默认设置:显示来自用户的索引谢谢你的回答!
connection.sync({force: false});
const Bar = sequelize.define('bar', { /* bla */ }, {
// disable the modification of table names; 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',
})