简体   繁体   English

在Heroku上运行迁移时,我得到PG :: Error:ERROR:关系“ member1_id”不存在

[英]When running migrations on Heroku, I get PG::Error: ERROR: relation “member1_id” does not exist

Locally, my migrations are fine (although I'm using SQLite. Will switch to postgresql on development asap). 在本地,我的迁移很好(尽管我正在使用SQLite。在尽快进行开发时将切换到postgresql)。

After resetting the database on Heroku with 使用以下命令在Heroku上重置数据库后

heroku pg:reset DATABASE

I ran 我跑了

heroku run rake db:migrate

But I am getting the following error after a migration: 但是在迁移后出现以下错误:

==  AddForeignKeysToCollaborations: migrating =================================
-- change_table(:collaborations)
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  relation "member1_id" does not exist
: ALTER TABLE "collaborations" ADD CONSTRAINT "collaborations_member1_id_id_fk" FOREIGN KEY ("member1_id_id") REFERENCES "member1_id"(id) ON DELETE CASCADE

Here is that migration: 这是迁移:

class AddForeignKeysToCollaborations < ActiveRecord::Migration
  def change
    change_table :collaborations do |t|
        t.foreign_key :member1_id, dependent: :delete
        t.foreign_key :member2_id, dependent: :delete
        end
  end
end

Previous migrations for Collaborations are 合作的先前迁移是

class CreateCollaborations < ActiveRecord::Migration
  def change
    create_table :collaborations do |t|
      t.integer :user_id
      t.integer :collaborator_id

      t.timestamps
    end
    add_index :collaborations, :collaborator_id
    add_index :collaborations, [:user_id, :collaborator_id], unique: true
  end
end

and

class UpdateCollaborations < ActiveRecord::Migration
  def change
    change_table :collaborations do |t|
      t.rename :user_id, :member1_id
      t.rename :collaborator_id, :member2_id
      t.string :status
    end
    add_index :collaborations,:member1_id
    add_index :collaborations,:member2_id
  end
end

Which are run in that order. 哪个按该顺序运行。 Why is this error coming up on Heroku? 为什么在Heroku上出现此错误? Specifically, it looks like PG is adding an unnecessary "_id" to "member1_id" 具体来说,似乎PG正在向“ member1_id”添加不必要的“ _id”

You're calling foreigner's methods with the wrong arguments. 您正在使用错误的参数调用外国人的方法。 The first argument is the referenced table name not the referencing column name. 第一个参数是引用的表名,而不是引用的列名。 And since your column names don't nicely match the table names you'll need :column options as well. 并且由于您的列名与表名不完全匹配,因此您也需要:column选项。 Something like this: 像这样:

t.foreign_key :users, :column => :member1_id, :dependent => :delete

That assumes that :users is the table name that your :member1_id and :member2_id columns should be pointing at. 假定:users是您的:member1_id:member2_id列应指向的表名。

The error message: 错误信息:

relation "member1_id" does not exist 关系“ member1_id”不存在

tells you that PostgreSQL is looking for a table called member1_id but can't find it. 告诉您PostgreSQL正在寻找一个名为member1_id的表,但找不到它。

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

相关问题 PGError:错误:当我在Heroku db:push中时,关系“ schema_migrations”不存在 - PGError: ERROR: relation “schema_migrations” does not exist when I heroku db:push PG ::错误:错误:关系“用户”在Heroku上不存在 - PG::Error: ERROR: relation “users” does not exist on Heroku Heroku迁移:PG ::错误:错误:关系“角色”不存在 - Heroku migration: PG::Error: ERROR: relation “roles” does not exist 全球化,Heroku:PG :: UndefinedTable:错误:关系不存在 - Globalize, Heroku: PG::UndefinedTable: ERROR: relation does not exist PG:错误关系不存在 - PG:Error relation does not exist 我运行 heroku 运行 rake db:migrate 但我收到错误 PG::UndefinedColumn: ERROR: 关系“tasks”的列“user_id”不存在 - I run heroku run rake db:migrate but I got error PG::UndefinedColumn: ERROR: column “user_id” of relation “tasks” does not exist PG ::错误:错误:关系“用户”不存在 - PG::Error: ERROR: relation “users” does not exist PG ::错误:错误:关系“可报告项”不存在 - PG::Error: ERROR: relation “reportables” does not exist PG :: UndefinedTable:错误:关系不存在 - PG::UndefinedTable: ERROR: relation does not exist PG :: UndefinedTable:错误:关系“音乐家”不存在 - PG::UndefinedTable: ERROR: relation “musicians” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM