# Stupid postgresql test fixtures

**URL:** <https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083>\
**Category:** Rails\
**Created:** [March 17, 2007, 2:48am UTC](https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083 "2007-03-17T02:48:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 17, 2007, 2:48am UTC](https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083/1 "2007-03-17T02:48:16Z")

</div>

Hi,

So, I’ve got a postgresql database with referential integrity on the  
foreign keys. It’s a pain in the ass because I get a ton of errors  
like this if I don’t have each test load fixtures in exactly the right  
order.

ActiveRecord::StatementInvalid: PGError: ERROR: update or delete on  
“users” violates foreign key constraint “user\_id\_fkey” on “bids”

DETAIL: Key (id)=(1) is still referenced from table “bids”.

: DELETE FROM users

How can I make it not such a pain?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 17, 2007, 4:16am UTC](https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083/2 "2007-03-17T04:16:22Z")

</div>

I guess I don’t get why I have to specify the fixtures used in each  
test. Shouldn’t all the fixtures be loaded and dropped via a  
transaction for each test?/

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 17, 2007, 11:09am UTC](https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083/3 "2007-03-17T11:09:49Z")

</div>

Hi Joe,

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

> > order.
> > 
> > ActiveRecord::StatementInvalid: PGError: ERROR: update or delete on  
> > “users” violates foreign key constraint “user\_id\_fkey” on “bids”
> > 
> > DETAIL: Key (id)=(1) is still referenced from table “bids”.
> > 
> > : DELETE FROM users
> > 
> > How can I make it not such a pain?

Please search the list archives for further discussion.

You can either declare all fixtures in test/test\_helper.rb so they’re  
all loaded, all the time, or preload the test database with your  
fixtures and never load or delete them unless they’ve changed. This is  
safe because all your test runs are wrapped in a transaction that’s  
rolled back at the end.

jeremy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 4, 2007, 3:02am UTC](https://www.ruby-forum.com/t/stupid-postgresql-test-fixtures/89083/4 "2007-04-04T03:02:31Z")

</div>

On Mar 17, 3:09 am, “Jeremy K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > So, I’ve got a postgresql database with referential integrity on the
> 
> > > How can I make it not such a pain?
> 
> Please search the list archives for further discussion.
> 
> You can either declare allfixturesintest/test\_helper.rb so they’re  
> all loaded, all the time, or preload thetestdatabase with yourfixturesand never load or delete them unless they’ve changed. This is  
> safe because all yourtestruns are wrapped in a transaction that’s  
> rolled back at the end.
> 
> jeremy

Can you give me an idea of what to search for? My first few searches  
came up with squat.
