首页 文章

在帆升降机上停止柱/工作台更换的方法

提问于
浏览
2

我正在使用风帆版0.11.2 . 以下是代码

config / 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 documentation,migrate:'safe'应该停止自动迁移,而不是更改数据库中的任何列或表 .

但仍然每次评论任何模型的属性并尝试提升sails应用程序时,与该属性关联的列将从mysql数据库中删除 .

注意:如果您需要任何其他信息或示例代码,请在评论时发表评论 .

1 回答

  • 0

    在每个模型中单独添加代码 migrate: 'safe' 已解决此问题 . 现在,文件consumer.js中的Consumer模型如下所示:

    /**
    * 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'
    };
    

    虽然解决方案有效,但我相信在所有模型中都没有涉及此代码声誉的更好的解决方案仍然存在 . 所以不要用这个答案来解决这个问题 .

相关问题