Is there a way to add a new column to a model that has already been defined?
Something like:
var Agency = sequelize.define("agency", {
agency_id: {
type: DataTypes.STRING(255),
primaryKey: true
},
agency_name: DataTypes.STRING(255),
agency_url: DataTypes.STRING(255)
});
Agency.addColumn({ agency_lang: DataTypes.STRING(2) });
theoretically you could do Agency.rawAttributes.agency_lang =...
and then call Agency.refreshAttributes
. However, there is no guarantee that this will work in all cases, since refreshAttributes
is not part of the public API.
Why do you need to alter the attributes after the model has been defined? Sequelize does not support automagically altering the table, so you'd need to DROP TABLE + CREATE TABLE
to reflect the new structure in the DB
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.