2013-02-11 61 views
1

前幾天我創建了用於添加Paperclip頭像的軌道遷移,但最終走向了一個不同的方向。作爲Rails的新手,我不知道如何像我一樣刪除遷移文件。已刪除的遷移和Heroku

我的應用程序工作正常本地,但運行時heroku run rake db:migrate我得到這個:

undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x000000046092e0> 

這是因爲它試圖運行遷移稱爲AddAttachmentAvatarToVenues,這是遷移我愣神刪除。

它也爲刪除遷移中指定的化身添加了列到schema.rb,但我創建了一個新的遷移來擺脫這些。新遷移擺脫了他們,但沒有改變heroku遷移錯誤。

任何想法如何解決這個問題?我做了大量的搜索和環顧,所以有很多人有類似的錯誤,他們大多是他們使用的命令的問題。

以下是在我的heroku遷移中嘗試刪除的遷移後的輸出。

== AddAttachmentAvatarToVenues: migrating ==================================== 
-- change_table(:venues) 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x00000003bdb7c8> 
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:4:in `block in up' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:in `change_table' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `block in method_missing' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `block in say_with_time' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:334:in `method_missing' 
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:3:in `up' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:370:in `up' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:389:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `call' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `ddl_transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in `block in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `each' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in `up' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

我確實看到輸出有什麼問題,我只是不確定如何解決它而不會搞亂它。

編輯:這裏的文件結構的一些截圖:

git

(兩個類似的命名者是因爲有一個專欄中,我忘了刪除,但是這是我在這個問題後沒「T影響它無論哪種方式)

structure

EDIT2:

這是從我的git歷史中刪除的遷移。在此之後,我添加了更多頻道。他們只是幾個字符串,但如果這可能會有所作爲,我會找到一個更新的版本。

class AddAttachmentAvatarToVenues < ActiveRecord::Migration 
    def self.up 
    change_table :venues do |t| 
     t.attachment :avatar 
    end 
    end 

    def self.down 
    drop_attached_file :venues, :avatar 
    end 
end 

在此先感謝!

+0

您能否顯示遷移? – 2013-02-11 18:31:37

+0

這就是問題所在,我從我的migrations文件夾中刪除了它,我不確定它會從哪裏來。 – Jason 2013-02-11 18:39:26

+0

它不在嗎? /app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb – 2013-02-11 18:40:18

回答

2

也許你應該看看這個:How to empty DB in heroku

所有正常的命令也是在Heroku上可用,唯一的區別是,你必須把Heroku的在它前面跑。

如果您的申請一直沒有去現場但你可以簡單地重新設置數據庫:

heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP 

並重新創建它,使用:

heroku run rake db:migrate 

種子數據庫:

heroku run rake db:seed 

最後,重啓Heroku:

heroku restart 

P.S.如果這些步驟沒有幫助,您可以嘗試在刪除數據庫後運行「heroku run rake db:setup」

+0

感謝您的幫助,不幸的是,當我這樣做時,'AddAttachmentAvatarToVenues:migrating'仍然嘗試並中止,導致我的其他遷移中止,就像以前一樣。 – Jason 2013-02-11 19:04:39

+0

你可以試試:heroku run rake db:rollback。所以你的遷移回滾到開始。然後,您可以創建具有所需屬性的遷移AddAttachmentAvatarToVenues。最後,你可以運行heroku run rake db:再次遷移。 – 2013-02-11 19:28:44

+0

可選:git rm [migration_number] _create_users.rb git push heroku master heroku run rake db:drop => heroku run rake db:create => heroku run rake db:migrate,請參閱:http://stackoverflow.com/questions/ 11023645/Heroku的 - 運行 - 耙dbmigrate錯誤 – 2013-02-11 20:40:37