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

时间:2015-11-17 20:09:39

标签: mysql node.js sails.js

我使用的是风帆版0.11.2。以下是

的代码
  

配置/ 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
};

根据风帆documentation,迁移:'安全'应该停止自动迁移,而不是更改数据库中的任何列或表。

但是每次对任何模型的属性进行注释并尝试提升sails应用程序时,与该属性关联的列都会从mysql数据库中删除。

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

1 个答案:

答案 0 :(得分: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'
};

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