I populated my development db with dummy data for 20 users using the Faker gem.
I forgot to include a “created_at” time, so they are now all ordered ahead of my hand-created detailed user records. I would like to either:
1) delete the 20 dummy users, and repopulate them with older “created_at” times, or
2) update the 20 dummy users’ “created_at” attributes with older times.
Option 1 is easy enough if there is a way to undo my initial population rake. Is there a way to do this?
Thanks!
In rails there is no option to remove data in database other than rake tasks.
In this case i think option 1 is better one as there is not much effort to be put. Since created_at is updated automatically while creation of recored you need not do that. You just need to delete data from users table.
Just type rails db in project folder in terminal and there type following command
It will delete last 20 users.
Create a new migration to add created_at column to table.
Run the rake task.
Everything will go perfect!
Thanks