1

有人可以帮我运行heroku run db:migrate吗?我已经忘记在heroku上运行db:migration和dev env上的迁移。我做了他们的coulple,现在我收到以下错误:PG :: UndefinedColumn:错误:关系“articles”的列“image_file_name”不存在

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迁移?

在此先感谢。

+0

似乎你的文章表不具有任何你正在试图删除列。 –

+0

我之前通过迁移删除了它。问题是当时我没有''heroku运行rake db:migrate',可能发生了太多其他更改。 – Wozane

回答

0

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

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

+0

我试过了,没有工作。 – Wozane

+0

你可以在这里列出你当前的错误吗? – user100693

+0

迁移到RemoveColumnImage(20160917131520) (为0.7ms)BEGIN == 20160917131520 RemoveColumnImage:迁移 - remove_column(:文章:映像文件,:字符串) (5.1ms)ALTER TABLE “物品” DROP “映像文件” (1.0ms)ROLLBACK (3.5ms)SELECT pg_advisory_unlock(96974639112725850) rake中止! StandardError的:发生错误,这和所有后来迁移取消: PG :: UndefinedColumn:ERROR:列关系的 “文章”, “映像文件” 不存在 :ALTER TABLE “物品” DROP “映像文件” – Wozane

相关问题