【发布时间】:2014-10-20 07:26:35
【问题描述】:
我一直在 SO 和 google 上研究这个问题,但我找不到任何可以告诉我如何删除特定迁移而不加载到 Heroku 中的信息。
我的问题是我在同一个项目中创建了多个迁移(我正在学习一个教程,我认为我跳过了一个步骤,而实际上我没有)现在当我试图将此数据库迁移到 Heroku我收到重复的迁移错误:
Running `rake db:migrate` attached to terminal... up, run.7535
rake aborted!
ActiveRecord::DuplicateMigrationNameError:
Multiple migrations have the name CreateUserFriendships
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:1011:in `validate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:917:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:807:in `new'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我很久以前删除了我的应用程序目录中的重复迁移文件以启动我的项目并在我的本地计算机上运行,现在在部署它时仍然引用这个重复但我不确定我需要去哪里删除它.
有人可以告诉我在哪里/如何删除这些重复的迁移吗?
谢谢, 编辑:我成功删除了其中一个迁移,但是当我运行“heroku run rake db:migrate”时,现在出现了一个不同的错误(在提交并推送到 heroku 之后):
Running `rake db:migrate` attached to terminal... up, run.2527
== 20141004220407 AddStateToUserFriendships: migrating ========================
-- add_column(:user_friendships, :state, :string)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "user_friendships" does not exist
: ALTER TABLE "user_friendships" ADD COLUMN "state" character varying(255)/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:395:in `add_column'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:649:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:621:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:621:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:641:in `method_missing'
/app/db/migrate/20141004220407_add_state_to_user_friendships.rb:3:in `change'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:595:in `exec_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:578:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:577:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:752:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:1038:in `ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:953:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:949:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:949:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我现在需要重新添加旧迁移吗?其中一个迁移的运行时间比另一个要晚,我应该将原来的迁移添加回我的程序文件并再次提交吗?
【问题讨论】:
标签: ruby-on-rails heroku