# Rails unit testing removes foreign key constraints in test database?

**URL:** <https://www.ruby-forum.com/t/rails-unit-testing-removes-foreign-key-constraints-in-test-database/133841>\
**Category:** Rails\
**Created:** [April 4, 2008, 7:15am UTC](https://www.ruby-forum.com/t/rails-unit-testing-removes-foreign-key-constraints-in-test-database/133841 "2008-04-04T07:15:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [April 4, 2008, 7:15am UTC](https://www.ruby-forum.com/t/rails-unit-testing-removes-foreign-key-constraints-in-test-database/133841/1 "2008-04-04T07:15:21Z")

</div>

I’ve noticed that when testing is finished that at some point Rails  
has removed the foreign key constraints from my test database. Does  
anyone know where this foreign key constraint deletion occurs in the  
source code. I’d like to turn it off.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [April 4, 2008, 8:40am UTC](https://www.ruby-forum.com/t/rails-unit-testing-removes-foreign-key-constraints-in-test-database/133841/2 "2008-04-04T08:40:08Z")

</div>

On Apr 3, 10:14 pm, Peter M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve noticed that when testing is finished that at some point Rails  
> has removed the foreign key constraints from my test database. Does  
> anyone know where this foreign key constraint deletion occurs in the  
> source code. I’d like to turn it off.

After much hunting, I found the issue. I needed to add the following  
to my environment.rb file

config.active\_record.schema\_format = :sql

Peter
