Sails.js migration - Instantiated Waterline model already has a `datastore` property

517 views Asked by At

While migrating to sails 1.0 I'm getting this error when I do a sails lift -

Error: Consistency violation: Instantiated Waterline model already has a `datastore` property

My config -

// config/datastores.js
module.exports.datastores = {
  default : {
    mySQL: {
      adapter: 'sails-mysql',
      url: 'mysql://username@localhost:3306/my_db'
    }
  }
}

// config/models.js
module.exports.models = {
  datastore: 'mySQL',
  migrate: 'drop',
  attributes: {
    // timezone-agnostic ISO 8601 JSON timestamp strings (e.g. '2017-12-30T12:51:10Z')
    createdAt: { type: 'string', autoCreatedAt: true, },
    updatedAt: { type: 'string', autoUpdatedAt: true, }
  }
};

// config/env/development.js
datastores: {
    mySQL: {
      adapter: 'sails-mysql',
      url: 'mysql://username@localhost:3306/my_db'
    }
  }
1

There are 1 answers

0
sgress454 On

In Sails 1.0, the default datastore is simply called default, and the best practice is to just configure default with whatever settings you need rather than creating a separately-named datastore like mySQL, unless you actually need multiple datastores in an app. So try:

// config/datastores.js
module.exports.datastores = {
  default : {
    adapter: 'sails-mysql',
    url: 'mysql://username@localhost:3306/my_db'
  }
}

// config/models.js
module.exports.models = {
  // No need for a `datastore` property; it will default to `default`.
  migrate: 'drop',
  attributes: {
    // timezone-agnostic ISO 8601 JSON timestamp strings (e.g. '2017-12-30T12:51:10Z')
    createdAt: { type: 'string', autoCreatedAt: true, },
    updatedAt: { type: 'string', autoUpdatedAt: true, }
  }
};

// No need for `datastores` property in config/env/development.js
// if you use the default datastore in development.