方法来停止帆升降列/表更换
我正在使用风帆版本0.11.2。 以下是代码
configuration/ models.js
在我的风帆应用程序
/** * Default model configuration * (sails.config.models) * * Unless you override them, the following properties will be included * in each of your models. * * For more info on Sails models, see: * http://sailsjs.org/#!/documentation/concepts/ORM */ module.exports.models = { connection: 'mysqldb', migrate: 'safe', schema : true };
根据sails 文档 ,迁移:“安全”应该停止自动迁移,不要更改数据库中的任何列或表。
但是还是每次注释一个属性的任何一个模型,并尝试解除sails应用程序,与属性关联的列从mysql数据库中删除。
注意:如果您需要任何附加信息或示例代码,请提出意见。
添加代码在每个模型中单独migrate: 'safe'
已经解决了这个问题。 现在,文件consumer.js中的消费者模型如下所示:
/** * Consumer.js * * @description :: TODO: You might write a short summary of how this model works and what it represents here. * @docs :: http://sailsjs.org/#!documentation/models */ module.exports = { migrate : 'safe', autoPK : true, autoCreatedAt: true, autoUpdatedAt: true, attributes : { name: { type : 'string', required : true, minLength: 3 }, email: { type : 'string', required: true, unique : true }, tableName : 'consumers' };
虽然解决scheme的工作原理,但我相信一个更好的解决scheme,不涉及所有模型中的代码声誉仍然在那里。 所以不要把这个问题标记为这个答案。