title: Foreign keys in postgresql can be violated by trigger
body: <p>I've created some tables in postgres, added a foreign key from one table to another and set ON DELETE to CASCADE. Strangely enough, I have some fields that appear to be violating this constraint.</p>
  
  <p>Is this normal behaviour? And if so, is there a way to get the behaviour I want (no violations possible)?</p>
  
  <p>Edit:</p>
  
  <p>I orginaly created the foreign key as part of CREATE TABLE, just using</p>
  
  <pre><code>... REFERENCES product (id) ON UPDATE CASCADE ON DELETE CASCADE
  </code></pre>
  
  <p>The current code pgAdmin3 gives is </p>
  
  <pre><code>ALTER TABLE cultivar
    ADD CONSTRAINT cultivar_id_fkey FOREIGN KEY (id)
        REFERENCES product (id) MATCH SIMPLE
        ON UPDATE CASCADE ON DELETE CASCADE;
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>To Clarify, I have a sneaking suspicion that the constraints are only checked when updates/inserts happen but are then never looked at again. Unfortunately I don't know enough about postgres to find out if this is true or how fields could end up in the database without those checks being run.</p>
  
  <p>If this is the case, is there some way to check all the foreign keys and fix those problems?</p>
  
  <p>Edit 3:</p>
  
  <p>A constraint violation can be caused by a faulty trigger, see below</p>