Reading across the web, it's unclear whether or not you need to update your model definitions in previously existing models for new columns created in the migration or create new model definitions for new tables created in the migration. Once a model definition file has been deployed, can/should it be updated? Or do updates to model definitions only exist in migration files?
After some time trying to figure this out, I had a QA with a dev who wrote a great article on sequelize db migrations here. My question and his response is as follows:
Q: One thing I don’t get is why you’re updating the model file as well as creating a migration file. I’m trying to update an existing, production db myself so I need to create a migration file. As far as I know, the model files I’ve created have been deployed and there is no use changing them now, the only way I can make an update to the db is only by way of migrations. So curious why you’re doing both here.
A: The migration modifies columns of tables in the database itself. The model is merely the way to inform Sequelize which columns it can expect to be present in the database. Eg you can have a kenzo column on your database, but if you don’t specify that in the model, you wont be able to use it in the code.
To try this out, you can add a field in the model without creating a migration for it, and then try to retrieve a record of that model. If the column is not added in the database, you will receive a column does not exist error.
There’s no harm in removing fields from your model if they are still present in the database though (although I would recommend also removing them through a migration).