简体   繁体   中英

How to Add column after, when table already have data using Sequelize in NodeJS?

I have models defined in the project, where I need column insertion is needed, for that I have just added the new column and its type to the particular model file.

Also tried with {alter:true} but not reflected in Database table.Also having error while inserting a new record, Unknown column 'isActive' in 'field list'

The error is because of your database is not updated with the new model, so it's normal. After updating your database successfully it won't be a problem.

It's hard to say anything before looking at the code but I guess your import (require) logic is the problem. Even if you fix that you are using sync function which is not good for production. It's just for testing purposes.

You should use sequelize migrations. With the help of it you can track your db changes and do not lose important data. It is a must in production but it's still good to use in development.

Read Sequelize Migrations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM