Reputation: 3108
We've some test data inside our production database and I'm trying to clean it up.
I was removing some test email addresses from the console directly.
User.where(:email=>"[email protected]").first.delete
This deleted that record.
Now when I'm trying to create another account with this same email address it says email is already taken.
I've done this several times in my dev environment, and it has worked like a charm.
I know I should never directly remove a record in prod from console, but this is an one-off scenario and I'm just curious why it is not working.
Please help me with this.
Upvotes: 2
Views: 3884
Reputation: 187
Try this in console
User.where(:email => "[email protected]").delete_all
Or if u want to delete all data
u = User.find("[email protected]")
u.delete
Upvotes: 5
Reputation: 1736
Are you using something like the Paranoia gem in production to soft-delete User records? If so, try User.with_deleted.where(:email=>"[email protected]")
and if that returns a result just change the user's email address to a non-existent one.
Upvotes: 2
Reputation: 8434
You are deleting only first record of your User table as per your command:
User.where(:email=>"[email protected]").first.delete
I think, there are multiple entries are there.!
You should to use delete_all with User object like below:
User.where(:email=>"[email protected]").delete_all
Upvotes: 1
Reputation: 2786
Every time for the operation with console you have to reload the console and the insert the record new one.
And one more thing, you are using first user with email so in you user model there should be some validation with email with uniq.
Upvotes: 0