[英]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.