Rename column with Rails using migration

1

I created a migration to rename a column and I 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 migration code is:

def change
   rename_column :users, :password, :password_digest
end
    
asked by anonymous 01.10.2016 / 20:33

2 answers

0

Dude, when I need to rename I do it as follows

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

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

When he makes the mistake with the self. I use without it ...

As our friend commented above, doing a rake db: rollback can help you sort out if you have a problem with some migration, but if it is replicated with production DO NOT and send it to production, just for testing.

I hope I have helped! Hugs!

    
05.10.2016 / 00:47
0

The error is probably in some old migration you made by adding a column with the wrong name. Try to run the rake db: rollback command after identifying the error.

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

If you can not get the db: roollback delete the table and re-create it.

    
04.10.2016 / 01:05