如何修复Heroku的迁移错误-Postgres

时间:2019-05-20 01:38:26

标签: node.js postgresql sqlite heroku migration

不确定我要去哪里。我查看了Knex.js docs,但在我的代码中没有发现任何问题。我的目标是从 Heroku 迁移到 Postgres ,但是此错误是唯一的阻止因素:

migration file "20190311161455_habits_table.js" failed
migration failed with error: alter table "habits" add constraint
"habits_categoryid_foreign" foreign key ("categoryId") references
"category" ("id") - relation "category" does not exist

这是我的代码:

exports.up = function(knex, Promise) {
  return knex.schema.createTable('habits', tbl => {
    tbl.increments();

    tbl.string('habitTitle');
    tbl.boolean('completed').defaultTo(false);
    tbl.integer('completionPoints').defaultTo(0);
    tbl
      .integer('userId')
      .unsigned()
      .notNullable()
      .references('id')
      .inTable('users');


    tbl
      .integer('categoryId')
      .unsigned()
      .notNullable()
      .references('id')
      .inTable('category');
    tbl.timestamp('created_at').defaultTo(knex.fn.now());
  });
};

exports.down = function(knex, Promise) {
  return knex.schema.dropTableIfExists('habits');
};

0 个答案:

没有答案