Sails: Error: Invalid data store identity. No data store exist with that identity.

Created on 26 Apr 2019  路  8Comments  路  Source: balderdashy/sails

Node version: 10.15.3
Sails version _(sails)_: 1.1.0
ORM hook version _(sails-hook-orm)_: ^2.1.1
Grunt hook version _(sails-hook-grunt)_: ^3.1.0
DB adapter & version _(e.g. [email protected])_: sails-mysql@latest


I just updated my sails 0.xxx to sails 1.1.0, I have made changes to the models, clearing up warnings and tried to setup the configuration.

However, I keep getting this error when I try to run it:

error: A hook (`orm`) failed to load!
error: Could not tear down the ORM hook.  Error details: Error: Invalid data store identity. No data store exist with that identity.
    at Object.teardown (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\helpers\teardown.js:60:26)
    at wrapper (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\@sailshq\lodash\lib\index.js:3250:19)
    at Deferred.parley.retry [as _handleExec] (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\machine\lib\private\help-build-machine.js:1076:19)
    at Deferred.exec (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\parley\lib\private\Deferred.js:286:10)
    at Deferred.switch (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\machine\lib\private\help-build-machine.js:1469:16)
    at teardownDatastore (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\lib\adapter.js:94:18)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\node_modules\async\dist\async.js:3047:20
    at replenish (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\node_modules\async\dist\async.js:884:21)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\node_modules\async\dist\async.js:888:13
    at eachLimit$1 (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\node_modules\async\dist\async.js:3136:26)
    at Object.<anonymous> (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\node_modules\async\dist\async.js:920:20)
    at Object.teardown (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\lib\adapter.js:89:13)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\lib\waterline.js:758:27
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:3047:20
    at eachOfArrayLike (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:1002:13)
    at eachOf (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:1052:9)
    at Object.eachLimit (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:3111:7)
    at Object.teardown (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\lib\waterline.js:742:11)
    at Hook.teardown (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\index.js:246:30)
    at Sails.wrapper (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\@sailshq\lodash\lib\index.js:3250:19)
    at Object.onceWrapper (events.js:277:13)
    at Sails.emit (events.js:189:13)

error: Failed to lift app: Exception: `registerDataStore` failed ("badConfiguration").  The configuration was invalid.  (Also got an additional error -- see `.raw`).
    at Object.registerDatastore (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-mysql\lib\adapter.js:54:17)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\lib\waterline.js:714:27
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:3047:20
    at eachOfArrayLike (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:1002:13)
    at eachOf (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:1052:9)
    at Object.eachLimit (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\node_modules\async\dist\async.js:3111:7)
    at Object.initialize (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\waterline\lib\waterline.js:650:11)
    at buildOntologyAndRunAutoMigrations (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\lib\build-ontology-and-run-auto-migrations.js:55:7)
    at async.auto._buildOntology (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\lib\initialize.js:456:7)
    at runTask (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1660:17)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1602:17
    at processQueue (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1612:17)
    at taskComplete (C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1630:13)
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1653:21
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:339:31
    at C:\Users\lawha\Desktop\Automed_new\Web-Portal\node_modules\sails-hook-orm\node_modules\async\dist\async.js:847:20

Process finished with exit code 0

This is my config.models:

module.exports.models = {

  fetchRecordsOnUpdate: true,
  fetchRecordsOnCreate: true,
  fetchRecordsOnCreateEach: true,

  //connection: 'remoteMySQL',
  datastore: 'default',
  connection: null,

  attributes: {
    createdAt: { type: 'string', autoCreatedAt: true, },
    updatedAt: { type: 'string', autoUpdatedAt: true, },

    id: { type: 'number', autoIncrement: true, }
  },

  dataEncryptionKeys: {
    default: 'PdsOZLHAwSUM8TlGN5GmhC1ivo7m9s/Z4gqi+BxCiAY='
  },

  migrate: 'safe'

};

This is my config.globals:

 module.exports.globals = {

   _: require('lodash'),

   async: require('async'),

   models: true,

   sails: true,

   services: true,

 };

This is my config.datastores (without revealing sensitive database info):

module.exports.datastores = {
  default:{
    adapter: require('sails-mysql'),
    url: "mysql://<username>:<password>@<host>/<database>",
    connectTimeout: 100000,
  },
};

I also have a production.js for production environment, development.js for development environment:

//production.js
module.exports = {

  datastores: {
    default: {
      // No need to set `adapter` again, because we already configured it in `config/datastores.js`.
      url: "<similar to default url in config.datastores>",
      connectTimeout: 100000,
    }
  }
......................
//development.js
module.exports = {

//It is using the default settings
  /*datastores: {
    default: {
      // No need to set `adapter` again, because we already configured it in `config/datastores.js`.
      url: "<....>",
      connectTimeout: 100000,
    }
  },*/

.................

I have also done a npm install of sails-hook-orm, sails-hook-sockets, sails-hook-grunt, and sails-mysql

helpful info or workaround mysql orm

Most helpful comment

@johnabrams7 I have managed to resolve the problem. So the real issue is not because of the packages, it is about setting "autoIncrement: true" in the database model.

My id for the tables are using UUID, so I thought setting autoIncrement: true is not necessary. However, I tested my model in a newly created project, and discovered that setting autoincrement to false, or not putting it causes the orm to fail.

I managed to get my project runs again by setting autoIncrement: true to all my id, even though they are using UUID. Do feel free to let me know if this setting might cause any issues.

All 8 comments

@HarrisAutomed Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. _(Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)_
  • tell us why this issue is important to you and your team. What are you trying to accomplish? _(Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)_
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. _(Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)_
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. _(Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)_
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. _(Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)_

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@HarrisAutomed - I wasn't able to reproduce this error in a new Sails app with all the same versions, adapter, and configuration you provided.

Can you try this out in a new Sails v1.1.0 app and configure your MySQL datastore in there to see if it still throws this error?

@johnabrams7 I just created a new Sails 1.0 project.

I having no problem running with the same configuration, until I tried adding the dependencies 1 by 1.

I managed to replicate the error by the npm install as below:

sails-sql
lodash
async
moment
randomstring
q ------------------------> (this installation causes the same error after I did a npm install, I think it belongs to this: https://www.npmjs.com/package/q)

Let me know if you manage to replicate the same thing.

@johnabrams7 I have managed to resolve the problem. So the real issue is not because of the packages, it is about setting "autoIncrement: true" in the database model.

My id for the tables are using UUID, so I thought setting autoIncrement: true is not necessary. However, I tested my model in a newly created project, and discovered that setting autoincrement to false, or not putting it causes the orm to fail.

I managed to get my project runs again by setting autoIncrement: true to all my id, even though they are using UUID. Do feel free to let me know if this setting might cause any issues.

@HarrisAutomed - Glad that worked out and thanks for providing the workaround! autoIncrement: true should be safe with UUID as far as I've seen - it basically increments the most recent record's value by one if nothing else is providing this value. MySQL only allows one auto-incrementing column per table.

On another note, we're currently developing a more powerful sails-sql adapter which also supports MySQL and adds more functionality and support beyond sails-mysql. Feel free to give it a try - hope this helps and thanks again!

I faced the same issue with MySQL adapter and datastore config. It got fixed when I used a plain alphanumeric mysql password without special characters. FYI my earlier password was "K!a(HK$%{K". Thanks for https://github.com/balderdashy/sails/issues/4069#issuecomment-495046633 for the tip!

I faced the same issue with MySQL adapter and datastore config. It got fixed when I used a plain alphanumeric mysql password without special characters. FYI my earlier password was "K!a(HK$%{K". Thanks for #4069 (comment) for the tip!

This worked for me as well.

To anyone that may stumble upon this (as of Sails v1.2.4), when using UUID's for your primary key, you DO NOT need to set autoIncrement, you just need to set required: true. @HarrisAutomed and @johnabrams7 thought you would like to know, so you could update your models to look & feel a bit nicer / a bit more proper.

Was this page helpful?
0 / 5 - 0 ratings