[英]Add and new column/attribute to sequelize model
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
. 从理论上讲,您可以执行Agency.rawAttributes.agency_lang =...
然后调用Agency.refreshAttributes
。 However, there is no guarantee that this will work in all cases, since refreshAttributes
is not part of the public API. 但是,由于refreshAttributes
不是公共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 Sequelize不支持自动更改表,因此您需要DROP TABLE + CREATE TABLE
来反映数据库中的新结构
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.