How to auto generate migrations with Sequelize CLI from Sequelize models?

Michael Schmidt picture Michael Schmidt · Jan 8, 2015 · Viewed 115.7k times · Source

I have a set of Sequelize models. I want to use migrations, not DB Sync.

Sequelize CLI seems to be able to do this, according to this article: "When you use the CLI for the model generation, you will gain the migration scripts for free as well."

How to auto generate the migrations with Sequelize CLI from existing Sequelize models?

Answer

john_mc picture john_mc · Dec 14, 2017

If you don't want to recreate your model from scratch, you can manually generate a migration file using the following CLI command:

sequelize migration:generate --name [name_of_your_migration]

This will generate a blank skeleton migration file. While it doesn't copy your model structure over to the file, I do find it easier and cleaner than regenerating everything. Note: make sure to run the command from the containing directory of your migrations directory; otherwise the CLI will generate a new migration dir for you