Hello,
I am currently working on a new project and I am trying to integrate 1 additional database into the project.
By following this tuto (Add new databases - Developer guide) I managed to get the 1 additional database. However, when I go to the forest administration site, I don’t know why my first database is not recognized anymore. Knowing that before integrating the new database, the 1st database works very well. On the other hand, the database that I integrated works well.
Here is the error that I currently have for one of my collections:
[forest] 🌳🌳🌳 Unexpected error: relation "public.users" does not exist
{
"name": "SequelizeDatabaseError",
"parent": {
"length": 111,
"name": "error",
"severity": "ERROR",
"code": "42P01",
"position": "33",
"file": "parse_relation.c",
"line": "1360",
"routine": "parserOpenTable",
"sql": "SELECT count(*) AS \"count\" FROM \"public\".\"users\" AS \"users\";"
},
"original": {
"length": 111,
"name": "error",
"severity": "ERROR",
"code": "42P01",
"position": "33",
"file": "parse_relation.c",
"line": "1360",
"routine": "parserOpenTable",
"sql": "SELECT count(*) AS \"count\" FROM \"public\".\"users\" AS \"users\";"
},
"sql": "SELECT count(*) AS \"count\" FROM \"public\".\"users\" AS \"users\";",
"stack": "SequelizeDatabaseError: relation \"public.users\" does not exist\n at Query.formatError (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/lib/dialects/postgres/query.js:354:16)\n at /Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/lib/dialects/postgres/query.js:71:18\n at tryCatcher (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)\n at Promise._settlePromiseFromHandler (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:547:31)\n at Promise._settlePromise (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:604:18)\n at Promise._settlePromise0 (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:649:10)\n at Promise._settlePromises (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:725:18)\n at _drainQueueStep (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/async.js:93:12)\n at _drainQueue (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/async.js:86:9)\n at Async._drainQueues (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/async.js:102:5)\n at Async.drainQueues [as _onImmediate] (/Users/jacquesliao/stage/nostrumcare-forest-gateway/Nostrum Care Gateway/node_modules/sequelize/node_modules/bluebird/js/release/async.js:15:14)\n at process.processImmediate (node:internal/timers:471:21)"
}
Hi @anon39940173
Name project is Nostrum Care Gateway and I am currently on the development environment.
All requests to type on my 1st database fail (list/count/get).
So for adding a database it works fine and when I do a forest schema:update I have the data of both databases in my .forestadmin-schema.json file but when I go to the forest admin platform, only the data of the database I added works and displays me fine, otherwise for my first database I have the error that I sent in my first post
Sorry again for letting this topic wait for so long, I’ve been super busy and could not find a way to keep up with support.
So I’ve setup a project with two postgres database, and finally managed to have the same error on my end by using different schema name for both databases.
Could this be what is happening on your end?
I’ve yet to find a satisfactory fix on my end, but can you try to:
Go to your .env file, and create a new environment variable (for instance DATABASE_SCHEMA_SECOND_DB)
Go to your models/your_second_db folder, and replace schema: process.env.DATABASE_SCHEMA by schema: process.env.DATABASE_SCHEMA_SECOND_DB
.env file
models/database_2/some_model.js
As a side note, the CLI does not seems to support using different schema names either (I did not see any parameter to provide the schema).
Did you have trouble when generating your model files? How did you solve them?
I did encounter difficulties when generating my template files. I was able to solve them by putting the same modeldir.
For example here I have the tables of my 1st database in white and those of the 2nd database in green
Concerning the test from the models I will tell you as soon as I finish the test.
You definitively can’t put all models in the same folder: if you do Forest Admin cannot know which models are from which database, and will always query the first one which explains the behavior you are having.
Now that the models were generated, can you split your models in two folders and update the modelsDir key in the configuration file?