Search Postgresql Archives

Re: Unit tests and foreign key constraints

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 21, 2015 at 12:39:01PM -0700, Andy Chambers wrote:
> Hey All,
> 
> I've started trying to use foreign key constraints in my schema but it
> seems to make it more difficult to write unit tests that touch the database
> because each test now requires more setup data to satisfy the foreign key
> constraint. (I know some say your unit tests shouldn't touch the DB but the
> more full stack tests I have, the better I sleep at night :-))
> 
> I wondered if anyone else has run into this problem and found a good
> strategy to mitigate it. I thought I might be able to make these
> constraints deferred during a test run since I have automatic rollback
> after each test but even after "set constraints all deferred", I still got
> a foreign key violation during my test run if the test tries to insert data
> with a non-existent foreign key.

Foreign keys aren't deferrable by default, you have to create them that
way...

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@xxxxxxxxx>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux