About database config

#1

I have problem with my config. The default Adonis load config of database in env file without read config/database.js :(( . I tried change config mysql in file database.js but nothing changed, Adonis always read from env. I remove all config value in env, and Adonis show a error " E_MISSING_DB_CONNECTION", but config in database.js is correct, and connection default is mysql.
And another problem, because adonis not load from database.js, i add “static function connection” in Model, but connection but not changed. example change to sqlite

ENV FILE

DB_CONNECTION=
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_DATABASE=

Database.js

connection: Env.get('DB_CONNECTION', 'mysql'),
...

  mysql: {
    client: 'mysql',
    connection: {
      host: Env.get('DB_HOST', '***********'),
      port: Env.get('DB_PORT', '***********'),
      user: Env.get('DB_USER', '***********'),
      password: Env.get('DB_PASSWORD', '***********'),
      database: Env.get('DB_DATABASE', '***********')
    },
    debug: Env.get('DB_DEBUG', false)
  },

And finally Adonis show error:

E_MISSING_DB_CONNECTION: Missing database connection {}. Make sure you define it inside config/database.js file > More details: https://err.sh/adonisjs/errors/E_MISSING_DB_CONNECTION

But the config in database is configured

If i config in ENV file, everything working good.

0 Likes

#2

Simply fill the fields in your .env file

0 Likes

#3

Ok, but i cannot change connection in Lucid. the “Static Function Connection” not working. How can i use it ? i working on two database.

0 Likes

#4

And if fill in the file ENV, so why we need fill in the database.js :smile:

0 Likes

#5

I never tried to database.js file in any of my applications.
You should use .env file instead as the official documentation says.
AdonisJs follows conventions, and one of those conventions is to use .env file for your database settings.

1 Like

#6

But i working on two database with two connection, but .env only support a connection. And Lucid supported many connection.

1 Like

#7

OH MY GOOD, It Simple, only delete or comment key in file ENV. :frowning: . Hope help another body.

1 Like