当改变表字段名时,sequelize不会更新字段名,只会递增。

我先用sequelize-auto 生成对应关系,只会运行时发现表的字段名写的有误,于是重新命名了表的字段名。将createdAt 改成了created_at


当我再次测试api的时候,发现sequelize对sql的查询语句出错了,如下


Executing (default): INSERT INTO `user` (`id`,`username`,`password`,`created_at`,`updated_at`,`createdAt`) VALUES (DEFAULT,'admin','12345',1507738177512,1507738177512,'2017-10-11 16:09:37');

server error { SequelizeDatabaseError: Unknown column 'createdAt' in 'field list'

即,createdAt这个字段还在sequelize里面,并没有被删除掉。求解。


aluckdog
浏览 463回答 1
1回答

缥缈止盈

原来sequelize会默认自动添加createdAt和updatedAt,这两个我的表里面没有,所以会报错。By default, Sequelize will add the attributes createdAt and updatedAt to your model so you will be able to know when the database entry went into the db and when it was updated last.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript