簡體   English   中英

這可以使用bookshelf.js進行遷移嗎?

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

我正在嘗試使用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');
  });
};

我試過跑:

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

但我的數據庫中沒有一個變化。 任何想法我怎么能讓它工作?

使用.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