Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

每次同步(sequelize.sync)并设置了表的对应关系,每次同步都会加一个外键 #51

Open
xiaojieajie opened this issue Jul 16, 2020 · 4 comments

Comments

@xiaojieajie
Copy link

xiaojieajie commented Jul 16, 2020

用nodemon来重启代码。
每次同步(sequelize.sync)并设置了表的对应关系

// 设置模型关系
const Class = require("./Class")
const Student = require("./Student")
Class.hasMany(Student);
Student.belongsTo(Class);

每次同步都会加一个外键
image

是不是同步在一个项目中只能同步一次啊

@demopark
Copy link
Owner

.sync({force:true})

@xiaojieajie
Copy link
Author

.sync({force:true})

用这个每次重启代码 表数据全没了呀

@demopark
Copy link
Owner

@xiaojieajie sync function 用于model和table之间的首次映射补全,会自动创建database中不存在的table或column. 在init过程结束后,如无调整不应反复调用sync方法(尤其是当结构并无改变时).

@xiaojieajie
Copy link
Author

@xiaojieajie sync function 用于model和table之间的_首次_映射补全,会自动创建database中不存在的table或column. 在init过程结束后,如无调整不应反复调用sync方法(尤其是当结构并无改变时).

好的 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants