2013-02-11 3 views
1

며칠 전 필자는 Paperclip 아바타를 추가하기 위해 레일을 마이그레이션했지만 다른 방향으로 나아갔습니다. Rails를 처음 접했을 때와 마찬가지로 마이그레이션 파일을 삭제하는 것이 얼마나 어려운 것인지 알지 못했습니다.삭제 된 마이그레이션 및 Heroku

내 응용 프로그램은 로컬에서 잘 작동하지만 heroku run rake db:migrate를 실행할 때 내가 얻을이 : 내가 바보 삭제 마이그레이션입니다 AddAttachmentAvatarToVenues라는 마이그레이션을 실행하려고하기 때문에

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

그것은이다.

또한 삭제 된 마이그레이션에서 지정한 schema.rb에 대한 아바타 열을 추가했지만이 마이그레이션을 제거하기 위해 새 마이그레이션을 만들었습니다. 새로운 마이그레이션을 통해 제거되었지만 영웅 마이그레이션 오류가 변경되지 않았습니다.

어떻게 해결할 수 있습니까? 나는 많은 인터넷 검색을했고 그렇게 주변을 둘러 보았고, 비슷한 오류를 가진 많은 사람들이 그들이 사용하는 명령에 대부분 문제가있는 동안 그렇게했다.

다음은 영웅 마이그레이션에서 삭제 된 마이그레이션을 시도한 후의 출력입니다.

== 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

(I 제거 깜빡 열이 있었기 때문에 두 개의 비슷한 이름의 사람이 있지만, 나는이 문제가 된 후에이었다 didn를

'는 t는

structure

EDIT2) 그것을 어느 쪽이든에 영향을 미칠 여기에 내 자식 기록에서 삭제 된 마이그레이션이 있습니다. 이 후에 몇 가지 채널을 추가했습니다. 그것들은 단지 두개의 문자열 이었지만 차이가 있다면 더 새로운 버전을 발견 할 것입니다.

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

마이그레이션을 표시 할 수 있습니까? –

+0

그게 문제입니다. 마이그레이션 폴더에서 파일을 삭제했는데 어디에서 왔는지 모르겠습니다. – Jason

+0

여기 없습니까? /app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb –

답변

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

+0

시도해 볼 수 있습니다 : heroku run rake db : rollback. 따라서 마이그레이션은 처음부터 다시 시작됩니다. 그런 다음 원하는 특성으로 마이그레이션 AddAttachmentAvatarToVenues를 만들 수 있습니다. 마지막으로 heroku를 실행하여 rake db를 실행할 수 있습니다. 다시 마이그레이션하십시오. –

+0

대체 방법 : git rm [migration_number] _create_users.rb git push heroku 마스터 heroku run rake db : drop => heroku run rake db : create => heroku run rake db : migrate, 참조 : http://stackoverflow.com/questions/ 11023645/heroku-run-rake-dbmigrate-error –

관련 문제