Re: Rows violating Foreign key constraint exists

Nandakumar M <[email protected]>
Newsgroups gmane.comp.db.postgresql.general
Message-ID <CANcFUu7gHMxK=px+zwt+mnX63-2ELU0nmLbYvP=GmL0+dERKXg@mail.gmail.com>
Hi,


> Have you verified that the FK is not in the parent table and is just not
> some index error/corruption?

Yes.

> >
> > Also, is there any way to make sure the FK checking trigger can never
> > be disabled (so that such a case will never arise)?
>
> Not sure that can happen as it is baked into existing code. For instance:
>
> https://www.postgresql.org/docs/11/app-pgdump.html
>
> "
> --disable-triggers
>
>      This option is relevant only when creating a data-only dump. It
> instructs pg_dump to include commands to temporarily disable triggers on
> the target tables while the data is reloaded. Use this if you have
> referential integrity checks or other triggers on the tables that you do
> not want to invoke during data reload.

Found this thread which discusses the same topic as here.
https://www.postgresql.org/message-id/20190715160926.GA17140%40alvherre.pgsql

PG already allows a new FK to be created with ADD CONSTRAINT ... NOT
VALID clause which can be validated later using ALTER TABLE ...
VALIDATE CONSTRAINT.
I guess what we are looking for here is the same but for existing FKs.

i.e Something like

`ALTER TABLE distributors ALTER CONSTRAINT distfk NOT VALID;`
`ALTER TABLE distributors VALIDATE CONSTRAINT distfk;`


Regards,
Nanda
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.