【发布时间】:2017-10-29 04:47:48
【问题描述】:
我正在尝试使用 MySQL 和 Knex 进行数据库迁移。
当我运行命令knex migrate:latest 时,我得到了
ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
我尝试在代码库上添加密码(到“123”和“否”),但最让我困惑的是,即使我的数据库文件中有user: "root",错误也会给出一个空字符串用户...
我分享我想象的相关文件:
// mysql_db.js
const knex = require('knex')({
client: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'SQL_Data',
},
});
module.exports = knex;
// knexfile.js
const path = require('path');
module.exports = {
development: {
client: 'mysql',
connection: {
filename: '/server/SQL/mysql_db',
},
migrations: {
directory: path.join(__dirname, '/server/SQL/migrations'),
},
seeds: {
directory: path.join(__dirname, '/server/SQL/seeds'),
},
},
};
//knex.js
const environment = proces.env.NODE_ENV || 'development';
const config = require('../../knexfile.js')[environment];
module.exports = require(knex)('config');
// "迁移定义"
exports.up = (knex, Promise) => knex.schema.createTable('sql_table', ((table) => {
table.increments();
table.string('name').notNullable();
table.string('email').notNullable();
table.string('description').notNullable();
table.string('url').otNullable();
}));
exports.down = (knex, Promise) => knex.schema.dropTable('sql_table');
【问题讨论】:
标签: mysql database database-migration knex.js