The problem is this: Postgres sets up foreign key constraints as “system triggers,” which can only be removed by a superuser. When database_cleaner tries to empty out your database between test runs, it tries to remove these keys, which causes the failure.

Currently there isn’t a “real” fix for this, but Sergey Potapov has bundled together the required hacks into a gem called rails3_pg_deferred_constraints. Pop it into your test group and you should be good to go.