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!
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! :)
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.