简体   繁体   English

这可以使用bookshelf.js进行迁移吗?

[英]Is this possible to use migrations with bookshelf.js?

I am trying to use migrations with knex and bookshelf, and so far thats my code, it is an example from the bookshelf documentation: 我正在尝试使用knex和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');
  });
};

I tried run: 我试过跑:

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

But not a single change in my database. 但我的数据库中没有一个变化。 Any ideas how I can get it working? 任何想法我怎么能让它工作?

Use .then() to create a chain of promises: 使用.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');
    });
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM