部署到Heroku PG :: DuplicateColumn:错误:

时间:2016-07-20 08:04:20

标签: ruby-on-rails json heroku reactjs devise

简而言之,我有一个带有Devise的Rails API,我想将它部署到Heroku,所以我可以在React应用程序中使用json文件。当我尝试将其迁移到Heroku时,它会给我错误:

" PG :: DuplicateColumn:ERROR:column" user_id"关系"评论"已经存在 :ALTER TABLE"评论"添加" user_id"整数"

有人告诉我删除迁移文件,因为不知何故Devise已经制作了它们,迁移文件会让它们加倍?无论如何它都没有帮助。

我不确定您是否需要它,但这是我的架构文件的样子:

ActiveRecord::Schema.define(version: 20160719152952) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "games", force: :cascade do |t|
    t.string   "title"
    t.text   "description"
    t.integer  "review_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  end

  add_index "games", ["review_id"], name: "index_games_on_review_id", using: :btree

  create_table "reviews", force: :cascade do |t|
    t.integer  "rating"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer  "user_id"
    t.integer  "game_id"
  end

  add_index "reviews", ["game_id"], name: "index_reviews_on_game_id", using: :btree
  add_index "reviews", ["user_id"], name: "index_reviews_on_user_id", using: :btree

  create_table "users", force: :cascade do |t|
    t.string   "email",                             default: "", null: false
    t.string   "encrypted_password",                default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",                     default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.inet     "current_sign_in_ip"
    t.inet     "last_sign_in_ip"
    t.datetime "created_at",                                     null: false
    t.datetime "updated_at",                                     null: false
    t.string   "authentication_token",   limit: 30
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree

  add_foreign_key "games", "reviews"
  add_foreign_key "reviews", "games"
  add_foreign_key "reviews", "users"
end

1 个答案:

答案 0 :(得分:1)

是的,我的猜测是迁移是重复的,因此运行两次,这会引发错误,因为索引列已经存在。

您无法通过运行类似的操作来使用迁移文件来访问数据库架构的终点;

heroku run rake db:schema:load

看看这是否有效。

但是 - 这有点奇怪;

add_foreign_key "reviews", "users"

您是否通过迁移添加了此内容?我通常不会为关系这样做,下面就足够了。看看你是否也可以删除add_foreign,因为我的视图中的索引就足够了(可能是抱歉)。

add_index "reviews", ["user_id"]