I wrongly named a column hased_password
instead of hashed_password
.
How do I update the database schema, using migration to rename this column?
I wrongly named a column hased_password
instead of hashed_password
.
How do I update the database schema, using migration to rename this column?
Just generate migration using command
After that edit the migration add following line in change method
This should do the trick.
I'm on rails 5.2, and trying to rename a column on a devise User.
the
rename_column
bit worked for me, but the singular:table_name
threw a "User table not found" error. Plural worked for me.Then change migration file to this:
Where :agent? is the old column name.
If you need to switch column names you will need to create a placeholder to avoid a duplicate column name error. Here's an example:
Run
rails g migration ChangesNameInUsers
(or whatever you would like to name it)Open the migration file that has just been generated, and add this line in the method (in between
def change
andend
):rename_column :table_name, :the_name_you_want_to_change, :the_new_name
Save the file, and run
rake db:migrate
in the consoleCheck out your
schema.db
in order to see if the name has actually changed in the database!Hope this helps :)
Generate the migration file:
# Creates db/migrate/xxxxxxxxxx.rb
Edit the migration to do your will.