【问题标题】:Is this possible to use migrations with bookshelf.js?这可以将迁移与 bookshelf.js 一起使用吗?
【发布时间】:2015-11-09 18:11:13
【问题描述】:

我正在尝试将迁移与 knex 和 bookshelf 一起使用,到目前为止,这就是我的代码,它是 bookshelf 文档中的一个示例:

exports.up = function(knex, Promise) {
  return knex.schema.createTable('books', function(table) {
    table.increments('id').primary();
    table.string('name');
  }).createTable('summaries', function(table) {
    table.increments('id').primary();
    table.string('details');
    table.integer('book_id').unique().references('books.id');
  });
};

我试过跑步:

knex migrate:make my_migration_name
knex migrate:latest
knex migrate:rollback

但我的数据库中没有任何更改。有什么想法可以让它工作吗?

【问题讨论】:

    标签: javascript node.js express bookshelf.js knex.js


    【解决方案1】:

    使用.then() 创建一个承诺链:

    exports.up = function(knex, Promise) {
      return knex.schema.createTable('books', function(table) {
        table.increments('id').primary();
        table.string('name');
      }).then(function() {
        return createTable('summaries', function(table) {
          table.increments('id').primary();
          table.string('details');
          table.integer('book_id').unique().references('books.id');
        });
      });
    };
    

    【讨论】:

      猜你喜欢
      • 2022-12-09
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      相关资源
      最近更新 更多