#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Foreign Key Not Work - Postgres


    I have created the following foreign key,

    ALTER TABLE ped_itens
    Ped_itens_idinsumo_fkey ADD CONSTRAINT FOREIGN KEY (idinsumo)
    REFERENCES bas_insumo (idinsumo) MATCH SIMPLE
    ON UPDATE NO ACTION ON DELETE NO ACTION;

    where I can not delete a product that is being used in a sales order, however the same does not work, someone could guide me the reason why it is not working, or someone already had the same problem.

    Postgres 8.2
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,788
    Rep Power
    349
    "does not work" is not a valid Postgres error message.

    Also: Postgres 8.2 is no longer supported. You should upgrade now
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Upgrade, definitely.

    And your problem... I can't tell from your explanation "where I can not delete a product" if this means your rule should or should not prevent this.

    Anyway, ON UPDATE NO ACTION ON DELETE NO ACTION has a lot to say about how effective this FK is with regard to related value deletions.

    And you really need to upgrade, at least to 8.4. There have been some good fixes. Updating to 9.2 is even better -- because 9.2 is awesome and 9.3 will be even better (materialized views should arrive!).

IMN logo majestic logo threadwatch logo seochat tools logo