删除了迁移和Heroku

几天前,我创建了一个轨道移植来添加Paperclip头像,但最终走向了一个不同的方向。 作为Rails的新手,我不知道如何像我一样删除迁移文件。

我的应用程序在本地工作正常,但运行时, 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)

我确实看到输出有什么问题,我只是不确定如何解决它,而不会搞乱它。

编辑:这是一些文件结构的截图:

混帐

(这两个类似的命名是因为有一列我忘了删除,但是这是在我遇到这个问题后,并没有影响它)

结构体

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

提前致谢!


也许你应该看看这个:如何在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

PS如果这些步骤没有帮助,可以在删除数据库后尝试运行“heroku run rake db:setup”

链接地址: http://www.djcxy.com/p/56899.html

上一篇: Deleted migrations and Heroku

下一篇: Rails rake db:migrate aborts with generated model