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?
Run the below command to create a migration file:
Then in the file generated in the
db/migrate
folder, writerename_column
as below:From API:
It renames a column but keeps the type and content remains same.
If the present data is not important for you, you can just take down your original migration using:
Without the quotes, then make changes in the original migration and run the up migration again by:
Simply create a new migration, and in a block, use
rename_column
as below.Rails 5 migration changes
eg:
if you want to change student_name column as name
Note:- if you not run rails db:migrate
You can do following steps
This will remove generated migration file, Now you can correct your column name
If you migrated(rails db:migrate), following options to change column name
Open your Ruby on Rails console and enter: