Jaseem Abbas
Jaseem Abbas

Reputation: 5230

How to use migrations in Sequelize?

I have used ORMS such as EntityFramework, Waterline and Mongoose. I just started using Sequelize. I have created a sample model. Later I wanted to add another column to the table corresponding to the same model. When I edit the model, the new field doesn't seem to be reflecting in the table unless I drop the table. Am I supposed to use Migrations? I got confused after reading the documentation. Could someone help me out?

Upvotes: 1

Views: 384

Answers (1)

swifty
swifty

Reputation: 1147

Yes, you should use migrations as if you edit a model in sequelize when you application starts it will only create the table if it doesn't exist. It does not check if the schema is different thus it doesn't update the schema of your table.

If I were you, I would install sequelize-cli and then run the sequelize init command. This sets up your project ready to use migrations.

Please note that we using sequelize migrations you have to explicitly define the primary key, updatedAt and createdAt columns otherwise they will not great created!

The docs are not too bad about migrations: http://sequelize.readthedocs.org/en/latest/docs/migrations/

Upvotes: 2

Related Questions