I have a model made with sequelize , I can not delete the data from the institution table , but now I must add a day field to it .
I already tried sequelize.sync
but it does not modify the structure of the table. and sequelize.sync({force:true}) would delete all the data.
It is important that you do not delete anything since it is a database that must be modified as the project grows.
The problem you raise (an evolving data model) is a common one. The solution I use in these cases is to create migrations .
Cheers
Using migrations is the most recommended way if you are in production. To perform a migration you simply need to write a file that exports an object with two functions:
These functions receive as a parameter an object of type
QueryInterface
and an instance of Sequelize. To make any type of change you want to do it in the up function .To change a column type just use the method
changeColumn
:Finally you must use the CLI to run your migration:
When the process is finished, your column should already be migrated. As a final recommendation, consult the documentation .