You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a little confused with when Sequelize creates the fields for associations.
I've created my migrations using sequelize-cli. This generated a migration and model file. Then in the model file I populated my associations. Then ran npx sequelize-cli db:migrate.
This creates the tables but not the foreign keys needed for the associations defined in the model.
I believe the docs could use some extra clarification, indeed. The behavior you are seeing is correct, in principle. The migration is something that changes the database according to what you told it to do, there isn't much extra magic behind the scenes, so you have to put the foreign keys explicitly in your migration.
I realized I could use the sync() method to have the database reflect the models. I don't see the point of the migration files however in that case. It's a lot simpler for me to setup the models then it is to go through and update migration files to add additional columns. Docs should be updated, it's not very clear.
Reacted by Pedro Augusto de Paula Barbosa and J. C. Lerebours A.
Activity
papb commentedon Aug 5, 2019
I believe the docs could use some extra clarification, indeed. The behavior you are seeing is correct, in principle. The migration is something that changes the database according to what you told it to do, there isn't much extra magic behind the scenes, so you have to put the foreign keys explicitly in your migration.
simkessy commentedon Aug 5, 2019
I realized I could use the sync() method to have the database reflect the models. I don't see the point of the migration files however in that case. It's a lot simpler for me to setup the models then it is to go through and update migration files to add additional columns. Docs should be updated, it's not very clear.
papb commentedon Aug 17, 2019
Let me keep this open to clarify the docs 👍