2013-02-11 87 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