cph*_*ill 2 sequelize.js sequelize-cli
我正在尝试使用Sequelize CLI工具运行数据库迁移,但是遇到一个问题,该工具未处理我的ENV变量。在github存储库中,它说在版本2.0.0(我在2.4.0中)中,您可以config/config.js像这样直接访问ENV变量process.env.DB_HOSTNAME,但是我收到一条错误消息,指示未传递任何值来自变量
错误:
Unable to connect to database: SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
Run Code Online (Sandbox Code Playgroud)
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"
},
}
Run Code Online (Sandbox Code Playgroud)
.env:
LOCAL_DATABASE="db_name"
LOCAL_USERNAME="root"
LOCAL_PASSWORD="test"
Run Code Online (Sandbox Code Playgroud)
您忘记了要求dotenv模块:
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"
},
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1636 次 |
| 最近记录: |