【问题标题】:Knex migrations don't create anythingKnex 迁移不会创造任何东西
【发布时间】:2015-05-25 20:24:44
【问题描述】:

我正在尝试开始使用 Knex.js,但似乎无法进行任何迁移。当我运行命令knex migrate:latest 时,数据库只有knex_migrations 表。

我是不是做错了什么?

Knexfile

module.exports = {
  development: {
    client: 'postgresql', //Also tried just 'pg'
    connection: {
      host: process.env.SERVER_HOST,
      user: process.env.SERVER_USER,
      password: process.env.SERVER_PASSWORD,
      database: 'mika_personal'
    }
  }
}

迁移

'use strict'

exports.up = function(knex, Promise) {
  knex.schema.createTable('blog_posts', function(table) {
    table.increments('id').primary()

    table.string('name', 75)
      .index()
      .unique()
      .notNullable()

    table.text('content')
    table.integer('views') 

    table.timestamps()
  })
}

exports.down = function(knex, Promise) {
  knex.schema.dropTable('blog_posts')   
}

【问题讨论】:

    标签: javascript node.js postgresql knex.js


    【解决方案1】:

    return 添加到 up 和 down 函数的第一行,以便 knex 可以访问 knex.schema.* 返回的承诺,然后 knex 可以使用它来协调执行迁移。例如:

    exports.down = function(knex, Promise) {
      return knex.schema.dropTable('blog_posts')   
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      相关资源
      最近更新 更多