Timmy Von Heiss
Timmy Von Heiss

Reputation: 2218

Rails 4 + Postrges Heroku: How can I clear all the data for a specific model?

I am using Heroku postgresql with my Rails 4 app.

My app has a Photo model which currently has 100 photos. I want to start over, deleting all of the existing photos so that the next uploaded photo will have photo_id: 1.

I found this answer but it appears that this would reset the entire database (meaning that all of my models would be reset instead of just the Photo model)?

Upvotes: 0

Views: 33

Answers (1)

Thanh
Thanh

Reputation: 8624

You can access to heroku rails console and run:

Photo.destroy_all
ActiveRecord::Base.connection.execute("TRUNCATE table_name RESTART IDENTITY")

table_name is name of table which stores photos.

Upvotes: 1

Related Questions