PG :: UndefinedColumn:ERROR:column" image_file_name"关系"文章"不存在

时间:2016-09-22 09:52:46

标签: ruby-on-rails postgresql heroku database-migration heroku-postgres

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

wozane:~/workspace (master) $ heroku run rake db:migrate                           
Running rake db:migrate on ⬢ wozane... up, run.7786
   (0.8ms)  SELECT pg_try_advisory_lock(96974639112725850);
  ActiveRecord::SchemaMigration Load (1.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to RemoveColumnImage (20160917131520)
   (0.7ms)  BEGIN
== 20160917131520 RemoveColumnImage: migrating ================================
-- remove_column(:articles, :image_file_name, :string)
   (1.5ms)  ALTER TABLE "articles" DROP "image_file_name"
   (0.7ms)  ROLLBACK
   (0.8ms)  SELECT pg_advisory_unlock(96974639112725850)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "image_file_name" of relation "articles" does not exist
: ALTER TABLE "articles" DROP "image_file_name"

案例是此列已被删除且不存在。

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

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

Schema.rb看起来像这样:

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

  create_table "articles", force: :cascade do |t|
    t.string   "title"
    t.text     "text"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "img_url"
  end

  create_table "photos", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "title"
    t.string   "img_url"
    t.text     "text"
  end

end

我在迁移过程中试图#整个代码,并且它没有帮助那些不起作用的评论:

rails db:environment:set RAILS_ENV=production
heroku run rake db:reset 
heroku run rake db:migrate -app wozane
heroku pg:reset DATABASE --confirm wozane

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

提前致谢。

1 个答案:

答案 0 :(得分:4)

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

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

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

相关问题