knex.js - 迁移最新 'Already Up To Date'

knex.js - migrate latest 'Already Up To Date'

当我 运行 knex migrate: latest 时,我得到以下内容,"Already up to date"。

你看,我之前 运行 成功迁移,但后来我使用 mySQL CLI 删除了那些表,因为我收到了这条 'Already up to date' 消息。我认为删除表格会迫使 knex 认识到它不是最新的。没用。

有什么指点吗?

这是我的文件:

knexfile.js:

require('dotenv').config();

module.exports = {

  development: {
    client: 'mysql',
    connection: {
      host: process.env.DATABASE_HOST_DEV || '127.0.0.1',
      user: process.env.DATABASE_USER_DEV,
      password: process.env.DATABASE_PASSWORD_DEV,
      database: process.env.DATABASE_NAME_DEV
    },
    migrations: {
      directory: __dirname+'/database/migrations'
    }
  },

  staging: {
    client: 'mysql',
    connection: {
      host: '127.0.0.1',
      user: 'root',
      password: 'password',
      database: 'recipes'
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: __dirname+'/database/migrations'
    }
  },

  production: {
    client: 'mysql',
    connection: {
      host: process.env.DATABASE_HOST,
      user: process.env.DATABASE_USER,
      password: process.env.DATABASE_PASSWORD,
      database: process.env.DATABASE_NAME
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: __dirname+'/database/migrations'
    }
  }

};

迁移:

exports.up = function(knex, Promise) {
    return Promise.all([
        knex.schema.hasTable('recipe').then((exists) => {
            if (!exists) {
                knex.schema.createTable('recipe', (table) => {
                    table.uuid('id');
                    table.string('name');
                    table.string('description');
                })
            }
        }),
        knex.schema.hasTable('ingredient').then((exists) => {
            if (!exists) {
                knex.schema.createTable('ingredient', (table) => {
                    table.uuid('id');
                    table.string('name');
                })
            }
        }),
        knex.schema.hasTable('recipe-ingredient').then((exists) => {
            if (!exists) {
                knex.schema.createTable('recipe-ingredient', (table)=> {
                    table.foreign('recipe_id').references('recipe.id');
                    table.foreign('ingredient_id').references('ingredient.id');
                    table.string('qty');  // <-- chose string instead of int because receipes include qty such as '1/3 cup', '1 teaspoon', etc.
                })
            }
        })
    ])
};

exports.down = function(knex, Promise) {
    return Promise.all([
        knex.schema.dropTable('recipe-ingredient'),
        knex.schema.dropTable('ingredient'),
        knex.schema.dropTable('recipe')
    ])
};

您可能需要删除任何与之前的迁移同名的迁移的日志,因为我之前在 postgres 上遇到过同样的问题。