Objection.js: no database connection available for a query. You need to bind the model class or the query to a knex instance.

Created on 25 Sep 2020  路  2Comments  路  Source: Vincit/objection.js

Hello,

I'm trying to setup my own project with objection and knex. I want to create a api backend.
But I run into this error: no database connection available for a query. You need to bind the model class or the query to a knex instance.
The project can be found here: https://github.com/eazyurk/shop-backend

I create the knex and objection setup in: src/db.js
The error is in: src/api/user/user.routes.js
The error will be logged when you go to: http://localhost:5050/api/v1/user

I already tried debugging it, I tried different mysql drivers. I'm 100% sure my database is working and running properly. I'm not sure where the error is coming from so I was hoping someone else could help me. Thanks a lot!

Most helpful comment

From what I can tell, no file in your app actually uses src/db.js. Try adding require('./db') somewhere near the root of your app to run the code in that module, perhaps inside src/app.js.

All 2 comments

From what I can tell, no file in your app actually uses src/db.js. Try adding require('./db') somewhere near the root of your app to run the code in that module, perhaps inside src/app.js.

@devinivy Thanks, that fixed it. I'm new to all this so kinda dumb mistake but I'm glad that you helped me! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apronin83 picture apronin83  路  3Comments

bsdo64 picture bsdo64  路  3Comments

sgangwisch picture sgangwisch  路  4Comments

purepear picture purepear  路  3Comments

AhmadRaza786 picture AhmadRaza786  路  3Comments