Rails Migration Error - StandardError: An error has occurred, this and all later migrations canceled:

4.6k views Asked by At

Using Rails 4.2, Ruby 2.2, OSX 10.10

I initially added a migration to my Movies table.

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

Then migrated to the database:

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) =======================

I then realized I put the wrong data type on the description field. So I created a migration file like:

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

I added the change method to the migration file 20150616130929_change_description_type_in_my_table.rb to edit the field type to text:

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

I then:

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)

So I attempted to rollback the database like 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)

Some SO answers suggest it is a SQLite 3 issue, but I doubt it because the rollback error would not occured (I believe).

0

There are 0 answers