Rails迁移错误 - StandardError:发生错误,此以及所有后续迁移都已取消:

时间:2015-06-16 13:44:26

标签: ruby-on-rails ruby sqlite rails-migrations

  

使用Rails 4.2,Ruby 2.2,OSX 10.10

我最初添加了一个迁移到我的电影表。

rails g migration addFieldsToMovies
      invoke  active_record
      create    db/migrate/20150616125848_add_fields_to_movies.rb

然后迁移到数据库:

rake db:migrate
== 20150616125848 AddFieldsToMovies: migrating ================================
-- add_column(:movies, :description, :description)
   -> 0.0006s
-- add_column(:movies, :release_date, :datetime)
   -> 0.0003s
== 20150616125848 AddFieldsToMovies: migrated (0.0009s) =======================

然后我意识到我在描述字段中输入了错误的数据类型。所以我创建了一个迁移文件,如:

rails g migration change_description_type_in_my_table
      invoke  active_record
      create    db/migrate/20150616130929_change_description_type_in_my_table.rb

我将change method添加到迁移文件20150616130929_change_description_type_in_my_table.rb,以将字段类型编辑为文字:

class ChangeDescriptionTypeInMyTable < ActiveRecord::Migration
  def change
    change_column :movies, :description, :text
  end
end

然后我:

rake db:migrate
== 20150616130929 ChangeDescriptionTypeInMyTable: migrating ===================
-- change_column(:movies, :description, :text)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:258:in `column'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:544:in `block (2 levels) in copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:537:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:537:in `block in copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:202:in `create_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:534:in `copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:527:in `move_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:520:in `block in alter_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:519:in `alter_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:483:in `change_column'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:662:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `block in say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:652:in `method_missing'
/Users/username/Documents/projectname/db/migrate/20150616130929_change_description_type_in_my_table.rb:3:in `change'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:606:in `exec_migration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:589:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:588:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:765:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/transactions.rb:220:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:956:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:820:in `up'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:798:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

所以我试图回滚数据库,如this SO Answer suggests

rake db:rollback
== 20150616125848 AddFieldsToMovies: reverting ================================
-- remove_column(:movies, :release_date, :datetime)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:258:in `column'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:544:in `block (2 levels) in copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:537:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:537:in `block in copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:202:in `create_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:534:in `copy_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:527:in `move_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:520:in `block in alter_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:519:in `alter_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:462:in `remove_column'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:662:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `block in say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:652:in `method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:497:in `block in revert'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:496:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:496:in `revert'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:604:in `exec_migration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:589:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:588:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:765:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/transactions.rb:220:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:956:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:827:in `down'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:907:in `move'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:809:in `rollback'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:125:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)

有些SO答案表明这是一个SQLite 3问题,但我对此表示怀疑,因为回滚错误不会发生(我相信)。

0 个答案:

没有答案