输入heroku run rake db:migrate
后,我看到了一个错误,
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "notified_bies" does not exist
: CREATE TABLE "notifications" ("id" bigserial primary key, "user_id" bigint, "notified_by_id" bigint, "post_id" bigint, "identifier" integer, "notice_type" character varying, "read" boolean, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_b080fb4855"
FOREIGN KEY ("user_id")
REFERENCES "users" ("id")
, CONSTRAINT "fk_rails_ff009aac1a"
FOREIGN KEY ("notified_by_id")
REFERENCES "notified_bies" ("id")
, CONSTRAINT "fk_rails_ff8a02c41d"
FOREIGN KEY ("post_id")
REFERENCES "posts" ("id")
)
,这是db文件夹中的迁移文件列表。
20180411215502_create_posts.rb
20180411215935_add_attachment_image_to_posts.rb
20180411225346_devise_create_users.rb
20180411230346_add_user_name_to_users.rb
20180411232041_add_user_id_to_posts.rb
20180412001819_create_comments.rb
20180412164718_add_attachment_avatar_to_users.rb
20180412164800_add_bio_to_users.rb
20180412193721_acts_as_votable_migration.rb
20180416212245_create_notifications.rb
20180416235802_create_follow_join_table.rb
20180416212245_create_notifications.rb
CreateNotifications < ActiveRecord::Migration[5.1]
def change
create_table :notifications do |t|
t.references :user, foreign_key: true
t.references :notified_by, foreign_key: true
t.references :post, foreign_key: true
t.integer :identifier
t.string :notice_type
t.boolean :read
t.timestamps
end
end
end
我会等你的建议谢谢你。
答案 0 :(得分:0)
看起来您没有将引用指向正确的表。例如,informed_by_id应该使用外键引用。从这个意义上说,“informed_bies”不存在。如果“informed_by_id”是users表中的值,则按如下所示添加
t.references :user
答案 1 :(得分:0)
创建外键时出现的错误
更新了答案
这是错误的原因
t.references :notified_by, foreign_key: true
现在,我不相信你有一个名为NotifiedBy
的模型,你试图在这里引用它。
也许你只需要在这个领域找到一个索引。因此,您可能需要将其更改为
t.integer :notified_by, index: true
旧答案
FOREIGN KEY ("notified_by_id")
REFERENCES "notified_bies" ("id")
, CONSTRAINT "fk_rails_ff8a02c41d"
您必须在20180416212245_create_notifications.rb
中创建引用或外键。
删除条目应解决问题