I am new to using SailsJS
and also I am using mongodb
for the database to connect. I tried using Robo 3T to make sure that my connection is valid and check that the models are in it. However, when I tried lifting using sails lift
I encountered this error:
error: A hook (`orm`) failed to load!
error:
error: Error: Consistency violation: A model (`calendar`) references a datastore which cannot be found (`warboard-test`). If this
model definition has an explicit `connection` property, check that it is spelled correctly. If not, check your default `connecti
on` (usually located in `config/models.js`). Finally, check that this connection (`warboard-test`) is valid as per http://sailsjs
.org/documentation/reference/configuration/sails-config-connections.
at validateModelDef (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\validate-model-def.js:110:11)
at G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\initialize.js:218:36
at arrayEach (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\node_modules\lodash\index.js:1289:13)
at Function.<anonymous> (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\node_modules\lodash\index.js:3345:13)
at Array.async.auto._normalizeModelDefs (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\initialize.js:216:11)
at listener (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:605:42)
at G:\projects\htdocs\warboard\node_modules\async\lib\async.js:544:17
at _arrayEach (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:85:13)
at Immediate.taskComplete [as _onImmediate] (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:543:13)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
error: Could not load Sails app.
error:
error: Tips:
error: First, take a look at the error message above.
error: Check that you're using the latest stable version of Sails.
error: Have a question or need help? (http://sailsjs.com/support)
I am pretty sure that I have a Calendar model and also it exists on my mongodb through GUI.
This is my config/connections.js
:
module.exports.connections = {
localDiskDb: {
adapter: 'sails-disk'
},
dbTest: {
adapter: 'sails-mongo',
url: 'mongodb://user:password@host:port/db?replicaSet=rs-ds117073',
socketOptions: {
keepAlive: 1000,
connectTimeoutMS: 60000
}
}
};
My config/models.js
:
module.exports.models = {
connection: 'db-test',
migrate: 'alter',
migrations: true,
version: 3
};
Sails: 1.0.0-46
Node: 8.9.4
Does anyone encounter this error?
Thanks in advance!
You have to change the line in config/models.js
from:
connection: 'db-test', // no match in connections.js
to:
connection: 'dbTest', // matches a key in connections.js
Then it will match the key name you give in your config/connections.js
file.