Express knex 迁移不创建数据库表

Express knex migrations do not create database tables

我正在使用带有 express 作为后端的 knex .. 这是 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'
    }
  }
};

我可以连接到数据库并且我已经从我的 express 中测试过它..我也可以使用 npx knex

创建迁移

cli 仅在终端上成功迁移会给出绿色成功消息...但是,数据库仍然有零 table。没有迁移 table 或任何 tables ..我什至删除了数据库并重新创建了另一个数据库......似乎 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' 尝试在开发和生产中更改它