更新:我做了$ 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: An error has occurred, this and all later migrations canceled:
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
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
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
本地应用也会返回无法找到“评论”表的问题。