0

I'm a beginner and I'm using Sequelize for my database. I created the model, did a migration after creating it, then added mocks & seeds but realized that I made a mistake for two attributes' data types. I need to change that but I'm not sure what the correct way to do this.

Do I have to:

sequelize db:migrate:undo

and then make my changes in the model and then run a migration?

Or do I have to drop the model and recreate it?

I guess, I'm not completely sure what a migration does in the scheme of things.

Kathy
  • 97
  • 1
  • 4
  • 12

1 Answers1

1

A migration will generate the sql queries and create the database tables.

A model tells sequelize about the table that the above migration created. For example, when you do User.create(), sequelize needs to know the table details to translate that into sql query.

I feel that as a beginner, you are probably better off creating the migrations yourself, rather than using the model to generate that.

Coming to your question , you can safely use sequelize db:migrate:undo to delete the tables.
As far as I know, sequelize db:migrate:undo method is not related to your model , so it does not matter if you edit it before or after the migration.

To be on the safe side, you can delete the tables first using migrate:undo and then edit the models and run the migrations again.

zacurry
  • 876
  • 3
  • 12
  • 25
  • I wasn't sure what the migrations affected, but your explanation helps make it clear. Thanks! – Kathy Apr 30 '18 at 13:30