views:

23

answers:

1

I'm trying to change a column in my sqlite DB via a migration...and I have no idea what I'm doing with RoR so please be gentle!

Here's the migration I'm trying to run.

class FixContactIdColumn < ActiveRecord::Migration
  def self.up
    rename_column :calls, :contact, :contact_id
  end

  def self.down
  end
end

And here's the exception it's generating.

brad@brad-vm:~/www/contactly$ vim db/migrate/20101013020151_fix_contact_id_column.rb
brad@brad-vm:~/www/contactly$ rake db:migrate --trace
(in /home/brad/www/contactly)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  FixContactIdColumn: migrating =============================================
-- rename_column(:calls, :contact, :contact_id)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass
/usr/lib/ruby/1.8/active_support/whiny_nil.rb:52:in `method_missing'
/usr/lib/ruby/1.8/active_record/connection_adapters/abstract/schema_definitions.rb:480:in `column'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:363:in `copy_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:357:in `each'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:357:in `copy_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:355:in `copy_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:349:in `move_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:342:in `alter_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:341:in `alter_table'
/usr/lib/ruby/1.8/active_record/connection_adapters/sqlite_adapter.rb:311:in `rename_column'
/usr/lib/ruby/1.8/active_record/migration.rb:352:in `send'
/usr/lib/ruby/1.8/active_record/migration.rb:352:in `method_missing'
/usr/lib/ruby/1.8/active_record/migration.rb:328:in `say_with_time'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/active_record/migration.rb:328:in `say_with_time'
/usr/lib/ruby/1.8/active_record/migration.rb:348:in `method_missing'
./db/migrate//20101013020151_fix_contact_id_column.rb:3:in `up_without_benchmarks'
/usr/lib/ruby/1.8/active_record/migration.rb:282:in `send'
/usr/lib/ruby/1.8/active_record/migration.rb:282:in `migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/active_record/migration.rb:282:in `migrate'
/usr/lib/ruby/1.8/active_record/migration.rb:365:in `__send__'
/usr/lib/ruby/1.8/active_record/migration.rb:365:in `migrate'
/usr/lib/ruby/1.8/active_record/migration.rb:486:in `migrate'
/usr/lib/ruby/1.8/active_record/migration.rb:560:in `call'
/usr/lib/ruby/1.8/active_record/migration.rb:560:in `ddl_transaction'
/usr/lib/ruby/1.8/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/usr/lib/ruby/1.8/active_record/transactions.rb:182:in `transaction'
/usr/lib/ruby/1.8/active_record/migration.rb:560:in `ddl_transaction'
/usr/lib/ruby/1.8/active_record/migration.rb:485:in `migrate'
/usr/lib/ruby/1.8/active_record/migration.rb:472:in `each'
/usr/lib/ruby/1.8/active_record/migration.rb:472:in `migrate'
/usr/lib/ruby/1.8/active_record/migration.rb:400:in `up'
/usr/lib/ruby/1.8/active_record/migration.rb:383:in `migrate'
/home/brad/www/contactly/vendor/rails/railties/lib/tasks/databases.rake:116
/usr/lib/ruby/1.8/rake.rb:636:in `call'
/usr/lib/ruby/1.8/rake.rb:636:in `execute
/usr/lib/ruby/1.8/rake.rb:631:in `each'
/usr/lib/ruby/1.8/rake.rb:631:in `execute'
/usr/lib/ruby/1.8/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:583:in `invoke'
/usr/lib/ruby/1.8/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2029:in `each'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2023:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2001:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28

Any ideas? I would be happy to provide additional details...

Update: It was suggested that I try to rollback my previous migration...but I get similar results.

-rw-r--r-- 1 brad brad  166 2010-10-12 17:21 20101013002111_add_notes_to_call.rb
-rw-r--r-- 1 brad brad  175 2010-10-12 17:22 20101013002240_add_contact_to_call.rb
-rw-r--r-- 1 brad brad  146 2010-10-12 19:25 20101013020151_fix_contact_id_column.rb
brad@brad-vm:~/www/contactly/db/migrate$ rake db:migrate VERSION=20101013002111
(in /home/brad/www/contactly)
==  AddContactToCall: reverting ===============================================
-- remove_column(:calls, :contact)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass

(See full trace by running task with --trace)
+1  A: 

Please post your original migration.

If your migration isn't in the production yet, just edit your original migration to fit what you need and run:

rake db:migrate VERSION=<migration_date>
rake db:migrate 

the migration_date is the timestamp that is in the name of the migration file. Remember also, you must pick the migration before the one that you plan to re execute, so if you have:

201010101005_create_users.rb
201010101010_create_calls.rb

You want to run:

rake db:migrate VERSION=201010101005
rafamvc
Hmm I tried what you suggested in got similar results. I updated my original post. Can you please provide any more direction? I *really* want to "get" RoR...
Brad Heller
Can you paste the original migration? The one that has the create for the table.
rafamvc