# Primary Keys enforcement vanishes in test database

**URL:** <https://www.ruby-forum.com/t/primary-keys-enforcement-vanishes-in-test-database/117399>\
**Category:** Rails\
**Created:** [October 16, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/primary-keys-enforcement-vanishes-in-test-database/117399 "2007-10-16T16:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [October 16, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/primary-keys-enforcement-vanishes-in-test-database/117399/1 "2007-10-16T16:48:08Z")

</div>

I use this naming convention for primary keys:

ActiveRecord::Base.primary\_key\_prefix\_type  
= :table\_name\_with\_underscore

I generate the MySQL test database: rake db:test:prepare, and although  
the column is there there is no primary key enforcement/index and no  
autoincrement (so activerecord saves fail). Is this a bug? What is  
the best workaround?

Alan

---

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [October 16, 2007, 10:47pm UTC](https://www.ruby-forum.com/t/primary-keys-enforcement-vanishes-in-test-database/117399/2 "2007-10-16T22:47:07Z")

</div>

On 10/16/07, Alan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I use this naming convention for primary keys:
> 
> ActiveRecord::Base.primary\_key\_prefix\_type  
> = :table\_name\_with\_underscore
> 
> I generate the MySQL test database: rake db:test:prepare, and although  
> the column is there there is no primary key enforcement/index and no  
> autoincrement (so activerecord saves fail). Is this a bug? What is  
> the best workaround?

Looks like a bug: [http://dev.rubyonrails.org/ticket/7085](http://dev.rubyonrails.org/ticket/7085)

Does using rake db:test:clone\_structure do the job? see  
[http://brighter.net/2007/8/15/keeping-your-test-db-in-sync](http://brighter.net/2007/8/15/keeping-your-test-db-in-sync)

---

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [October 17, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/primary-keys-enforcement-vanishes-in-test-database/117399/3 "2007-10-17T18:31:53Z")

</div>

That’s the ticket!

rake db:test:clone\_structure  
is the successful workaround

Thanks!
