Rails-путаница с миграциями

Я надеюсь, что кто-то может помочь мне разобраться в этом без необходимости воссоздавать весь мой бэкэнд.

I’M using Rails and was having trouble deploying to Heroku. Когда я бежал

$ heroku run rake db:migrate

моя миграция не удалась, потому что у меня была миграция, которая отбросила таблицу, которая не существовала. Случилось так, что у меня была таблица Relations, которую я переименовал в SchoolCityType ( единственное число ).

Эта миграция, которая отбрасывала таблицу, отбрасывала SchoolCityType s (множественное число, как и должно быть ).

Проблема: я удалил файл миграции вместо его отката, но Heroku по-прежнему не запускает команду.

Что мне делать? Спасибо заранее.

heroku сообщение об ошибке миграции:

== 20160407014126 DropSchoolDistrictCityTypesTable: migrating =================
-- drop_table(:school_district_city_types)
   (1.7ms)  DROP TABLE "school_district_city_types"
PG::UndefinedTable: ERROR:  table "school_district_city_types" does not exist
: DROP TABLE "school_district_city_types"
   (1.1ms)  ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:`== 20160407014126 DropSchoolDistrictCityTypesTable: migrating =================
-- drop_table(:school_district_city_types)
   (1.7ms)  DROP TABLE "school_district_city_types"
PG::UndefinedTable: ERROR:  table "school_district_city_types" does not exist
: DROP TABLE "school_district_city_types"
   (1.1ms)  ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR:  table "school_district_city_types" does not exist
: DROP TABLE "school_district_city_types"
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:116:in `drop_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20160407014126_drop_school_district_city_types_table.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  table "school_district_city_types" does not exist
: DROP TABLE "school_district_city_types"
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:116:in `drop_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20160407014126_drop_school_district_city_types_table.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
PG::UndefinedTable: ERROR:  table "school_district_city_types" does not exist
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:116:in `drop_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20160407014126_drop_school_district_city_types_table.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate`

3 ответа

  1. откат можно выполнить даже при удалении миграций.

    Я предлагаю вам вернуться на удобную для вас позицию и работать оттуда с новыми миграциями.

    Надеюсь, это помогло

  2. Похоже, вы удалили файл миграции, который создает ‘school_district_city_types’. Теперь вы пытаетесь удалить таблицу, которая не существует/создана ранее. Просто удалите файл миграции ‘20160407014126’, который удаляет эту таблицу.

  3. Вы должны иметь возможность просто удалить файл миграции. В будущем напишите свои миграции так:

    drop_table :school_district_city_types if (table_exists? :school_district_city_types)
    

    и вы никогда не будете иметь эту проблему снова.