且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不创建带有 Sequelize 的外键

更新时间:2023-02-02 23:33:18

创建表后(在数据库中)是否添加了关系?
如果您修改方案并再次运行程序,则需要 .sync({ force: true }).如果该表在数据库中尚不存在,Sequelize 只会创建该表及其所有引用.

Did you add the relation after creating the table ( in the database ) ?
You need .sync({ force: true }) if you modify your scheme's and run your program again. Sequelize will only create the table and all it's references if the table does not exist yet in the database.

是否在所有关联都建立后调用同步?

Are you calling sync after all associations have been made ?

你在使用 InnoDB 吗?

Are you using InnoDB ?

奇怪的是,我可以重现这一点,我认为最简单的解决方法是手动定义密钥,这就是我解决的方法,可能是一个错误,否则我不确定.

Oddly enough I can reproduce that, The easiest fix is to define the key manually I think, that's how I solved it, Might be a bug otherwise I'm not sure.

请看这里:http://sequelizejs.com/docs/latest/associations#block-3-line-24