July 12th, 2013, 09:51 AM
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.
July 12th, 2013, 10:22 AM
"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.
Tips on how to ask better questions:
July 12th, 2013, 05:54 PM
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!).