# PostgreSQL CASCADE not copied to test db

**URL:** <https://www.ruby-forum.com/t/postgresql-cascade-not-copied-to-test-db/72569>\
**Category:** Rails\
**Created:** [February 24, 2006, 12:17am UTC](https://www.ruby-forum.com/t/postgresql-cascade-not-copied-to-test-db/72569 "2006-02-24T00:17:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolfmanjm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/3da27b/32.png) [@wolfmanjm](https://www.ruby-forum.com/u/wolfmanjm)\
**Post date:** [February 24, 2006, 12:17am UTC](https://www.ruby-forum.com/t/postgresql-cascade-not-copied-to-test-db/72569/1 "2006-02-24T00:17:45Z")

</div>

When the unit test harness creates a test database from the  
development database, the ON DELETE CASCADE constraints I have on my  
foreign keys are not copied into the test database. (I can tell by  
looking at db/development\_structure.sql.)

That means the fixtures can’t load/unload from the test database  
properly. In other words, all my tests fail with the same error  
message:

ActiveRecord::StatementInvalid: PGError: ERROR: update or delete on  
“orders” violates foreign key constraint  
“redeemed\_coupons\_order\_id\_fkey” on “redeemed\_coupons”  
DETAIL: Key (id)=(1) is still referenced from table “redeemed\_coupons”.

Is this a bug or intended behavior? If it is intended behavior, then  
what am I doing wrong?

Thanks for your help.

## Jim

Jim M., removed\_email\_address@domain.invalid, removed\_email\_address@domain.invalid  
[http://www.io.com/~jimm](http://www.io.com/~jimm)

---

<div class="post-metadata">

**Author:** ![wolfmanjm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/3da27b/32.png) [@wolfmanjm](https://www.ruby-forum.com/u/wolfmanjm)\
**Post date:** [February 24, 2006, 5:02am UTC](https://www.ruby-forum.com/t/postgresql-cascade-not-copied-to-test-db/72569/2 "2006-02-24T05:02:07Z")

</div>

On 2/23/06, Jim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When the unit test harness creates a test database from the  
> development database, the ON DELETE CASCADE constraints I have on my  
> foreign keys are not copied into the test database. (I can tell by  
> looking at db/development\_structure.sql.)

Never mind; I was wrong. Some combination of deleting  
db/development\_structure.sql and recreating my development or test  
databases fixed the problem. The ON DELETE CASCADE constraints are  
indeed inside db/development\_structure.sql and are copied.

Sorry about coming to the list with this problem. I spent hours trying  
to figure out why I was getting the error message in the original  
post. Sigh.

## Jim

Jim M., removed\_email\_address@domain.invalid, removed\_email\_address@domain.invalid  
[http://www.io.com/~jimm](http://www.io.com/~jimm)
