2015-11-17 21 views
2

我正在使用風帆版本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數據庫中刪除。

注意:如果您有任何疑問,請在您需要任何附加信息或示例代碼時發表評論。

+0

你能向我們展示config/models.js的所有代碼嗎?您正在使用哪種版本的風帆? – piscator

+0

@piscator我已經用config/models.js和sails版本的完整文件更新了這個問題。 – TarunJadhwani

+0

嘗試將架構選項移動到您使用的每個模型,架構:true, connection:'mysqldb', tableName:'yourTable', attributes:{} –

回答

0

單獨在每個模型中添加代碼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' 
}; 

雖然解決方案的工作,但我相信,一個更好的解決方案,不涉及所有型號這段代碼的口碑還是在那裏。所以不要將這個問題標記爲用這個答案解決。