Express knex迁移不创建数据库表



我使用express作为后端。这是knexfile

module.exports = {
development: {
client: 'postgresql',
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations',
directory: './src/knex/migrations'
},
seeds: {
directory: './src/knex/seeds'
}
},
production: {
client: 'postgresql',
connection: {
database: 'my_db',
user: 'username',
password: 'password'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
}
};

我可以连接到数据库,我已经测试了,从我的快递。我也可以使用npx knex

创建迁移和cli仅在终端上迁移成功,给出绿色成功消息…但是,数据库仍然没有表。没有迁移表或任何表。我甚至删除了数据库并重新创建了另一个…似乎cli不与实际的Postgres服务器连接…任何想法。

用户迁移

exports.up = function (knex, Promise) {
return knex.schema.createTable('users', function (table) {
table.increments();
table.string('email').notNull();
table.string('password').notNull();
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
table.timestamp('deleted_at');
});
};
exports.down = function (knex, Promise) {
return knex.schema.dropTable('users');
};

postgresql的客户端应该是'pg'而不是'postgresql'尝试在开发和生产中同时更改它

相关内容

最新更新