balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.81k stars 1.95k forks source link

Error: Invalid data store identity. No data store exist with that identity. #4749

Open HarrisAutomed opened 5 years ago

HarrisAutomed commented 5 years ago

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. sails-mysql@5.55.5): 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

sailsbot commented 5 years ago

@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:

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.

johnabrams7 commented 5 years ago

@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?

HarrisAutomed commented 5 years ago

@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.

HarrisAutomed commented 5 years ago

@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.

johnabrams7 commented 5 years ago

@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!

seethun commented 4 years ago

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!

abid1208 commented 4 years ago

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.

neonexus commented 4 years ago

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.

Revadike commented 2 years ago

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.

Doing so requires me to manually set the id each time I want to insert data in the db, instead of it being generated for me.

Revadike commented 2 years ago

The workaround that works for me is doing this:


    "primaryKey":       "id",
    "dontUseObjectIds": true,
    "attributes":       {
        "createdAt": { "type": "number", "autoCreatedAt": true },
        "updatedAt": { "type": "number", "autoUpdatedAt": true },
        "id":        { "type": "number", "columnName": "_id", "autoIncrement": true, "unique": true },