I am trying to run a db migration with the Sequelize CLI tool, but I'm running into an issue where my ENV variables are not being processed by the tool. In the github repo, it says in version 2.0.0 (I'm on 2.4.0) you can directly access ENV variables in config/config.js
like so, process.env.DB_HOSTNAME, but I get an error that indicates that no values are being passed in from the variables
Error:
Unable to connect to database: SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
config.js:
module.exports = {
"development": {
"username": process.env.LOCAL_USERNAME,
"password": process.env.LOCAL_PASSWORD,
"database": process.env.LOCAL_DATABASE,
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
},
}
.env:
LOCAL_DATABASE="db_name"
LOCAL_USERNAME="root"
LOCAL_PASSWORD="test"
you forgot to require dotenv
module:
require('dotenv').config(); // this line is important!
module.exports = {
"development": {
"username": process.env.LOCAL_USERNAME,
"password": process.env.LOCAL_PASSWORD,
"database": process.env.LOCAL_DATABASE,
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With