关系不存在问题



我在迁移db

时遇到了问题
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

迁移给我

== 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"))

我什至已经评论了create_table方法下方change中的所有内容,并且仍然给出相同的错误。

你能告诉我为什么会发生这种情况吗?

它期望posts表可能由Post模型支持。尝试编辑CreateBlogoTaggings迁移文件。用blogo_post_id替换post_id的所有出现,然后再次运行迁移。

最新更新