# Test database does not have constraints

**URL:** <https://www.ruby-forum.com/t/test-database-does-not-have-constraints/109448>\
**Category:** Rails\
**Created:** [July 15, 2007, 1:54am UTC](https://www.ruby-forum.com/t/test-database-does-not-have-constraints/109448 "2007-07-15T01:54:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 15, 2007, 1:54am UTC](https://www.ruby-forum.com/t/test-database-does-not-have-constraints/109448/1 "2007-07-15T01:54:45Z")

</div>

I added some db specific constraints. I wanted to test them and tweak  
them. So, I have unit tests. But, I was amazed to see all of the pass  
the first time.

So, I looked and the test database does not have any constraints. I’m  
using PostgreSQL. Is there an option to rake db:test:prepare ?

Thank you,  
Perry

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 15, 2007, 2:38am UTC](https://www.ruby-forum.com/t/test-database-does-not-have-constraints/109448/2 "2007-07-15T02:38:45Z")

</div>

On Jul 14, 2007, at 18:54 , Perry S. wrote:

> I added some db specific constraints.

> So, I looked and the test database does not have any constraints.

How did you add the db-specific constraints? I suspect you need to use  
config.active\_record.schema\_format = :sql  
in environment.rb.

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 15, 2007, 6:40am UTC](https://www.ruby-forum.com/t/test-database-does-not-have-constraints/109448/3 "2007-07-15T06:40:59Z")

</div>

Perry S. wrote:

> I added some db specific constraints. I wanted to test them and tweak  
> them. So, I have unit tests. But, I was amazed to see all of the pass  
> the first time.
> 
> So, I looked and the test database does not have any constraints. I’m  
> using PostgreSQL. Is there an option to rake db:test:prepare ?

I’m not sure why this isn’t one tiny bit smoother, but you typically  
have to  
use lines like

rake RAILS\_ENV=test db:migrate  
rake RAILS\_ENV=test db:test:prepare  
rake RAILS\_ENV=test db:fixtures:load

You only need to do the first one, once, after adding migrations that  
add  
new database details. I don’t think normal development requires the  
second  
two. The deal is ‘rake test’ internally switches RAILS\_ENV to test mode,  
but  
most other rake commands do not.

In extremis (meaning very often) we must ‘drop database’ inside our  
database  
(MySquirrel) to then run db:migrate to get a fresh and up-to-date  
version.

And props for unit testing!

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
