# Migrating data to multiple tables?

**URL:** <https://www.ruby-forum.com/t/migrating-data-to-multiple-tables/110012>\
**Category:** Rails\
**Created:** [July 21, 2007, 6:43am UTC](https://www.ruby-forum.com/t/migrating-data-to-multiple-tables/110012 "2007-07-21T06:43:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbadone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7feea3/32.png) [@zbadone](https://www.ruby-forum.com/u/zbadone)\
**Post date:** [July 21, 2007, 6:43am UTC](https://www.ruby-forum.com/t/migrating-data-to-multiple-tables/110012/1 "2007-07-21T06:43:48Z")

</div>

Hello,

I’m trying to create a data migration for a new project I’m working  
on. I have numerous tables and would like to be able to populate the  
MySql db with test data.

I get the data to appear in the tables but the linking (has\_many,  
has\_one, etc.) don’t seem to connect to each record properly. The area  
I’m talking about is the id field of each record. I can get the  
linking of the tables but the id of the records are starting from 15  
of so each time.

±—±----------±--------+  
| id | client\_id | address |  
±—±----------±--------+  
| 33 | 1 | 1 |  
| 34 | 2 | 2 |  
| 35 | 3 | 3 |  
| 36 | 1 | 4 |  
±—±----------±--------+

Now this db has been through a number of migrations, both forward and  
backwards (Version=0).  
Is this something I’m overlooking in Rails or is this a MySql problem?

thanks  
Jeffrey

---

<div class="post-metadata">

**Author:** ![zbadone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7feea3/32.png) [@zbadone](https://www.ruby-forum.com/u/zbadone)\
**Post date:** [July 22, 2007, 9:03pm UTC](https://www.ruby-forum.com/t/migrating-data-to-multiple-tables/110012/2 "2007-07-22T21:03:30Z")

</div>

This happened to me once, I didn’t know what to do also 🙂

But as “Dan M.” said, if you drop your table the auto increment will  
reset to ZERO again.

---

<div class="post-metadata">

**Author:** ![zbadone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7feea3/32.png) [@zbadone](https://www.ruby-forum.com/u/zbadone)\
**Post date:** [July 22, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/migrating-data-to-multiple-tables/110012/3 "2007-07-22T20:55:35Z")

</div>

Knowing what is wrong without seeing the migrations is difficult, but  
you can reset the auto\_increment value on a table:  
ActiveRecord::Base.connection.execute “ALTER TABLE people  
AUTO\_INCREMENT = 1;”

It sounds like the auto\_incrementing is continuing, but that shouldn’t  
happen if you’re completely dropping your tables by going down to  
database version 0.

Hope that helps,  
Dan M.  
[http://www.dcmanges.com](http://www.dcmanges.com)
