Ruby on rails 关系不存在问题
迁移数据库时遇到问题Ruby on rails 关系不存在问题,ruby-on-rails,ruby,ruby-on-rails-4,database-migration,Ruby On Rails,Ruby,Ruby On Rails 4,Database Migration,迁移数据库时遇到问题 class CreateBlogoTaggings < ActiveRecord::Migration def change taggings_table = "#{Blogo.table_name_prefix}taggings" create_table(taggings_table) do |t| t.integer :post_id, null: false t.integer :tag_id , null: fa
class CreateBlogoTaggings < ActiveRecord::Migration
def change
taggings_table = "#{Blogo.table_name_prefix}taggings"
create_table(taggings_table) do |t|
t.integer :post_id, null: false
t.integer :tag_id , null: false
end
add_index taggings_table, :tag_id, unique: true
add_index taggings_table, :post_id, unique: true
if defined?(Foreigner)
tags_table = "#{Blogo.table_name_prefix}tags"
posts_table = "#{Blogo.table_name_prefix}posts"
add_foreign_key taggings_table, tags_table , column: :tag_id
add_foreign_key taggings_table, posts_table, column: :post_id
end
end
end
我甚至对create\u table
方法下面的change
中的所有内容都进行了注释,但仍然给出了相同的错误
你能告诉我为什么会发生这种情况吗?它期望一个
posts
表可能由Post
模型支持。尝试编辑CreateBlogoTaggings
迁移文件。将所有出现的post\u id
替换为blogo\u post\u id
,然后再次运行迁移。您的应用程序中是否有post
模型?数据库中是否有posts表?@Muaad没有,但我有blogo\u posttable@Raaz这就是问题所在。它期望一个posts
表可能由Post
模型支持。尝试编辑CreateBlogoTaggings
迁移文件。将所有出现的post\u id
替换为blogo\u post\u id
,然后再次运行迁移。@NarasimhaReddy这有什么关系?如果我对create_table方法下面的代码进行注释,它是否只是在表中创建列??
== 20180215114117 CreateBlogoTaggings: migrating ==============================
-- create_table("blogo_taggings")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "posts" does not exist
: CREATE TABLE "blogo_taggings" ("id" serial primary key, "post_id" integer NOT NULL, CONSTRAINT fk_blogo_taggings_post_id FOREIGN KEY ("tpost_id") REFERENCES "posts" ("id"))