Reputation: 2889
I generated a User model using this command:
rails generate model User name:string date_birth:date age:int...
As you can see I made a mistake. I entered a date of birth and an age. Now I also migrated into a mySql database. Is there any way to just delete the age field?
Edit: Is it also possible to add a field?
Upvotes: 7
Views: 12916
Reputation: 21616
You can also edit your migration file and remove the column which you don't need from the migration file, and then rake db:migrate
again.
Upvotes: 0
Reputation: 20724
At least two choices:
rake db:rollback
, delete the field from the migration and then re-run rake db:migrate
rails generate migration new_migration
.Upvotes: 2
Reputation: 1284
Run the following in terminal
rails destroy model User
This should reverse the generate so you can start again
Upvotes: 0
Reputation: 1085
Create a new migration with
rails g migration migrationname
and in the migration's up method run the following
remove_column :users, :age
run rake db:migrate and you are good to go.
Upvotes: 22