简体   繁体   中英

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:

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:

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');
    });
  });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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