1

大家好,下面是我的用户表模型代码...

module.exports = {

attributes: {
firstName: 'string',
lastName: 'string',
age: 'integer',
birthDate: 'date',
emailAddress: 'email'
}
};

它正在创建user具有上述属性的表..但是在我们从后端插入一些数据到数据库表user之后......重新启动sails / nodejs..它开始替换用户表,所以里面的所有数据user都会丢失。 ..如何解决这个问题?这样它就不会创建相同的表,如果它已经存在......

4

1 回答 1

1

You need to configure the model settings for this. Either change your model like this:

module.exports = {

    migrate: 'safe',

    attributes: {
        firstName: 'string',
        lastName: 'string',
        age: 'integer',
        birthDate: 'date',
        emailAddress: 'email'
    }

};

Or if you are using sails version 0.10.x, then you can also make this setting global by changing the config/models.js file:

module.exports.models = {
  migrate: 'safe'
};

Local settings in each model if present will override global settings

于 2014-11-27T07:49:25.093 回答