PG::UndefinedColumn:错误:关系“articles”的列“image_file_name”不存在

Woz*_*ane 2 postgresql ruby-on-rails heroku database-migration heroku-postgres

有人可以帮我跑步heroku run db:migrate吗?我忘记在heroku 上运行db:migration 以及在dev env 上运行migration。我做了几个,现在收到以下错误:

\n\n
wozane:~/workspace (master) $ heroku run rake db:migrate                           \nRunning rake db:migrate on \xe2\xac\xa2 wozane... up, run.7786\n   (0.8ms)  SELECT pg_try_advisory_lock(96974639112725850);\n  ActiveRecord::SchemaMigration Load (1.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"\nMigrating to RemoveColumnImage (20160917131520)\n   (0.7ms)  BEGIN\n== 20160917131520 RemoveColumnImage: migrating ================================\n-- remove_column(:articles, :image_file_name, :string)\n   (1.5ms)  ALTER TABLE "articles" DROP "image_file_name"\n   (0.7ms)  ROLLBACK\n   (0.8ms)  SELECT pg_advisory_unlock(96974639112725850)\nrake aborted!\nStandardError: An error has occurred, this and all later migrations canceled:\n\nPG::UndefinedColumn: ERROR:  column "image_file_name" of relation "articles" does not exist\n: ALTER TABLE "articles" DROP "image_file_name"\n
Run Code Online (Sandbox Code Playgroud)\n\n

情况是该列已被删除且不存在。

\n\n

错误消息中提到的迁移(编号20160917131520):

\n\n
class RemoveColumnImage < ActiveRecord::Migration[5.0]\n  def change\n    remove_column :articles, :image_file_name , :string\n    remove_column :articles, :image_content_type, :string\n    remove_column :articles, :image_file_size, :integer\n    remove_column :articles, :image_updated_at, :datetime\n  end\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n

Schema.rb 看起来像这样:

\n\n
ActiveRecord::Schema.define(version: 20160921115118) do\n\n  create_table "articles", force: :cascade do |t|\n    t.string   "title"\n    t.text     "text"\n    t.datetime "created_at", null: false\n    t.datetime "updated_at", null: false\n    t.string   "img_url"\n  end\n\n  create_table "photos", force: :cascade do |t|\n    t.datetime "created_at", null: false\n    t.datetime "updated_at", null: false\n    t.string   "title"\n    t.string   "img_url"\n    t.text     "text"\n  end\n\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试#迁移整个代码,但它对那些不起作用的注释没有帮助:

\n\n
rails db:environment:set RAILS_ENV=production\nheroku run rake db:reset \nheroku run rake db:migrate -app wozane\nheroku pg:reset DATABASE --confirm wozane\n
Run Code Online (Sandbox Code Playgroud)\n\n

有谁知道如何在我的情况下运行 heroku 迁移?

\n\n

提前致谢。

\n

She*_*ary 5

只需注释掉删除列迁移的代码即可。

class RemoveColumnImage < ActiveRecord::Migration[5.0]
  def change
    #remove_column :articles, :image_file_name , :string
    #remove_column :articles, :image_content_type, :string
    #remove_column :articles, :image_file_size, :integer
    #remove_column :articles, :image_updated_at, :datetime
  end
end
Run Code Online (Sandbox Code Playgroud)

并尝试运行heroku run rake db:migrate -app wozane