Your Friend
Your Friend

Reputation: 1149

NodeJs sails model replacing existing table

Hello people below is my model code for an user table...

module.exports = {

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

It is creating user table with the above mentioned attributes..but after after we insert some data from back end to database table user ... after restarting sails / nodejs .. it starts replacing the user table, so that all data inside user will be lost... how to fix this? so that it does not create the same table if it already exists...

Upvotes: 1

Views: 266

Answers (1)

Mandeep Singh
Mandeep Singh

Reputation: 8224

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

Upvotes: 1

Related Questions