我希望有人可以幫助我解決這個問題,而無需重新創建我的整個後端。Rails - 與遷移混淆
我正在使用Rails,並且在部署到Heroku時遇到了問題。當我跑
$ heroku run rake db:migrate
我的遷移失敗,因爲我有一個遷移,刪除了一個不存在的表。發生了什麼是我有一張名爲關係的表,並將其更名爲SchoolCityType(單數)。
這種遷移該刪除的表被丟棄SchoolCityType 小號(複數,因爲它應該是)。
問題:我刪除了遷移文件而不是回滾,但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`
這是不是很清楚你在問什麼。如果您刪除了遷移文件,則應該沒有問題。請包含Heroku日誌中的錯誤消息。 – meagar
我剛剛添加了它。謝謝 –
根據日誌,「20160407014126_drop_school_district_city_types_table」仍然存在,正試圖放下你的桌子。如果該表不再存在於任何數據庫中,則可以簡單地刪除該文件。如果您想維護遷移,因爲您的應用程序的某些實例可能擁有該數據庫,那麼您可以在Heroku上簡單地創建一個名稱正確的空表,以便遷移可以成功完成。 – meagar