I am able to run migrate command when I specify the database name, user and password directly. But when I provide with env variable/value. It says no database selected. I have installed npm i dotenv
npx sequelize-cli db:migrate
dotenv is required.
require('dotenv').config();
module.exports = {
development: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'mysql',
logging: false
},
test: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'mysql',
logging: false
},
production: {
use_env_variable: 'DATABASE_URL'
}
};
I have the following in .env file thus:
DB_USER=root
DB_PASS=
DB_NAME=road_rescue_dev
DB_HOST=127.0.0.1
This works
development: {
username: "root",
password: "",
database: road_rescue_dev,
host: process.env.DB_HOST,
dialect: 'mysql',
logging: false
},