Issue PG::DuplicateTable: ERROR: relation "comments" already exists - Heroku migration 在Heroku迁移过程中出现问题:PG::DuplicateTable错误:关系“comments”已经存在
Issue PG::DuplicateTable: ERROR: relation "comments" already exists - Heroku migration 在Heroku迁移过程中出现问题:PG::DuplicateTable错误:关系“comments”已经存在
更新:我执行了 $heroku run rake db:schema:load
,并且在追踪中不再看到错误,但是我仍然无法运行应用程序。
我正在将本地应用上传到Heroku。在我的gemfile中为生产环境设置pg后,我遇到了一些问题。我的日志返回一个PG::DuplicateTable: ERROR: relation "comments" already exists
错误,所以我通过执行rails db并删除名为'comments'的表来解决这个问题,因为我遵循了Stackoverflow上某人的建议。问题是在执行git push heroku master
和run rake db:migrate
之后,我仍然遇到同样的错误信息。
完整的追踪信息如下:
StandardError: 发生了错误,此次以及之后的迁移将被取消: PG::DuplicateTable: ERROR: relation "comments" already exists : CREATE TABLE "comments" ("id" serial primary key, "user_id" integer, "holder_id" integer, "commentable_id" integer, "commentable_type" character varying(255), "commentable_url" character varying(255), "commentable_title" character varying(255), "commentable_state" character varying(255), "anchor" character varying(255), "title" character varying(255), "contacts" character varying(255), "raw_content" text, "content" text, "view_token" character varying(255), "state" character varying(255) DEFAULT 'draft', "ip" character varying(255) DEFAULT 'undefined', "referer" character varying(255) DEFAULT 'undefined', "user_agent" character varying(255) DEFAULT 'undefined', "tolerance_time" integer, "spam" boolean DEFAULT 'f', "parent_id" integer, "lft" integer, "rgt" integer, "depth" integer DEFAULT 0, "created_at" timestamp, "updated_at" timestamp) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing' /app/db/migrate/20140619200026_the_comments_create_comments.the_comments_engine.rb:4:in `change' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:595:in `exec_migration' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 leve
schema.rb
# encoding: UTF-8 # 此文件是根据数据库的当前状态自动生成的。请使用Active Record的迁移功能进行数据库的逐步修改,然后再生成此模式定义。 # # 请注意,此schema.rb定义是您数据库模式的权威源。如果您需要在另一个系统上创建应用程序数据库,应使用db:schema:load,而不是从头开始运行所有迁移。后者是一种有缺陷和不可持续的方法(迁移越多,运行速度越慢,问题的可能性越大)。 # # 强烈建议您将此文件纳入版本控制系统。 ActiveRecord::Schema.define(version: 20140626173923) do create_table "hacks", force: true do |t| t.text "description" t.string "image" t.string "url" t.datetime "created_at" t.datetime "updated_at" t.string "picture" t.string "image_file_name" t.string "image_content_type" t.integer "image_file_size" t.datetime "image_updated_at" t.integer "draft_comments_count", default: 0 t.integer "published_comments_count", default: 0 t.integer "deleted_comments_count", default: 0 t.integer "user_id" end add_index "hacks", ["user_id"], name: "index_hacks_on_user_id" create_table "identities", force: true do |t| t.integer "user_id" t.string "provider" t.string "uid" t.datetime "created_at" t.datetime "updated_at" end add_index "identities", ["user_id"], name: "index_identities_on_user_id" create_table "taggings", force: true do |t| t.integer "tag_id" t.integer "taggable_id" t.string "taggable_type" t.integer "tagger_id" t.string "tagger_type" t.string "context", limit: 128 t.datetime "created_at" end add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true create_table "tags", force: true do |t| t.string "name" t.integer "taggings_count", default: 0 end add_index "tags", ["name"], name: "index_tags_on_name", unique: true create_table "users", force: true 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.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" t.string "name" t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.integer "my_draft_comments_count", default: 0 t.integer "my_published_comments_count", default: 0 t.integer "my_comments_count", default: 0 t.integer "draft_comcoms_count", default: 0 t.integer "published_comcoms_count", default: 0 t.integer "deleted_comcoms_count", default: 0 t.integer "spam_comcoms_count", default: 0 end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true create_table "votes", force: true do |t| t.integer "votable_id" t.string "votable_type" t.integer "voter_id" t.string "voter_type" t.boolean "vote_flag" t.string "vote_scope" t.integer "vote_weight" t.datetime "created_at" t.datetime "updated_at" end add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope" add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope" end
本地应用程序也返回无法找到 'comments' 表的问题。