sequelize/express-example

duplicate foreignKey when using sequelize.sync()

tonghoai opened this issue · 3 comments

I'm using models like files in models folder. But when i'm using sequelize.sync() some models duplicated foreginKey like following

image

This is my associate

image

image

image

image

Have 3 foreginKey but sequelize has created 6 foreginKey. Anybody can help me? Thank you!

remjx commented

Each belongsTo and hasMany creates one foreign key. It may make sense to use both in situations like this so you can run joins both ways Sequelize querying syntax. If you'll only need to join A to B and not B to A, you don't need both. At least that is my

I tried removing belongsTo and it works, but duplicator only appears in some models, awesome!

papb commented

Hello @tonghoai, are you still experiencing this issue with duplicate foreign keys? If yes, I would like to ask you to open an issue in the main repo.

I will close this issue for now, but let me know if you think it should be reopened.