# Clean all records

**URL:** <https://www.ruby-forum.com/t/clean-all-records/128075>\
**Category:** Rails\
**Created:** [February 4, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075 "2008-02-04T20:25:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/1 "2008-02-04T20:25:48Z")

</div>

hi @ all  
How can I clean all records from a table in a mysql database without  
delete the table in the database? (only use a method in the model)

thanks for helping!

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/2 "2008-02-04T21:04:25Z")

</div>

Take a look at destroy\_all

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001384)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

Aaron

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/3 "2008-02-04T21:06:47Z")

</div>

Actually, delete\_all might be a better bet in this case because it  
runs without instantiating the records first.

Aaron

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/4 "2008-02-04T23:31:25Z")

</div>

On Feb 4, 2:23 pm, “K. R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can I overwrite the table with the old structure of the table? Can I use  
> for this scenario the rake tool? So all records are deleted and the old  
> structure still the same.

Is this for your development environment and are you using test  
fixtures? If so you can easily load test fixtures into your  
development database by running “rake db:fixtures:load”.

Aaron

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/5 "2008-02-04T22:23:03Z")

</div>

Can I overwrite the table with the old structure of the table? Can I use  
for this scenario the rake tool? So all records are deleted and the old  
structure still the same.

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 4, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/clean-all-records/128075/6 "2008-02-04T23:35:49Z")

</div>

Aaron wrote:

> Is this for your development environment and are you using test  
> fixtures?

No, but I want to copy / overwrite an existing table with rake in the  
same environment. Is it possible with rake? Or with an other solution?

For example: I have a table people and I want to copy this table into  
the guests table.
