Subject Re: Foreign key violation, where there isn't
Author Adam
--- In firebird-support@yahoogroups.com, "Sandor Tamas"
<sandortamas@...> wrote:
>
> Hi,
>
> I have a problem:
> I have to tables, one has a PK, the other has a FK for the previous
> table's PK.
> But then, when I try to post new record, it sais I have a violation of
> Foreign key on table. It is strange, because I tried it by hand, and
> with IBExpert's help to choose the proper record from the primary table.
>
> Even when I tried it without foreign key, I was able to insert the
> record, but then, it dropped me an error creating the foreign key.
>
> Is there something I don't know about foreign keys, or is there
> something FB doesn't know about my foreign keys? :-)
>
> Any advices welcome!

It may be a number of things that others have already mentioned. If
you want a straight forward single answer, you really need to create a
repeatable test case to demonstrate what you are talking about. The
test case should be reproducible using iSQL or any other tool.
Otherwise we may be looking at bugs in your preferred admin tool.

Obviously, the parent record must exist, committed and visible to the
current transaction. If there are concurrent pending changes to the
primary key that are not visible to your transaction, then Firebird
can obviously not allow you to achieve this.

What may not be so obvious is a bug/artifact in Firebird where any
change to the parent record (including updates to fields unrelated to
the foreign key) can cause a foreign key violation when inserting
records in the child table.

http://tracker.firebirdsql.org/browse/CORE-1606

Adam