Rename column with Rails using Migration

Asked

Viewed 679 times

1

I created a Migration to rename a column and only get the error;

Undefined method `to_sym' for nil:Nilclass

== 20161001182840 RenameColumnPasswordInUsersPasswordToPasswordDigest: migrating                                  
-- rename_column(:users, :password, :password_digest)                                                             
rake aborted!                                                                                                     
StandardError: An error has occurred, this and all later migrations canceled:                                     

undefined method `to_sym' for nil:NilClass  

the code of the Migration is:

def change
   rename_column :users, :password, :password_digest
end
  • Whoa, did it work? So, today I had a problem with Migration here at the company, I had to go to the database and manually delete Migration inside the table "schema_migration" and run the rake db:migrate again, but it was no problem with changing name not... hehe, just to share! : D

2 answers

0


Man, when I need to rename I do it like this

def self.up
  rename_column :users, :password, :password_digest
end

def self.down
  rename_column :users, :password_digest, :password
end

When he mistakes with the self. I use without it...

Like our friend commented above, make a rake db:rollback can help you solve case had any problem in some Migration, however, if it is replicated with the in production DON’T and send it to production, just for testing.

I hope I helped! Hug!

0

Probably the error is in some old Migration you made by adding a column with the wrong name. Tries to execute the command rake db:rollback after identifying the error.

For example, if you added a column with the type :inteer, or :strig, when it was supposed to be :integer or :string, respectively.

If you cannot give db:roollback delete the table and create it again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.