Subject RE: [firebird-support] Foreign key violation, where there isn't
Author Alan McDonald
> 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!
>
> Thanks,
> SanTa

Unfortunately FKs will accept NULL values unless your FK field is set to not
null. This can lead to confusion in this instance. So without a foreign key
reference in your insert statement, the insert will work. I have to suspect
that your interface (the one other than IBExpert) for the insert is not
putting the correct value in the FK field.
Do you have a trigger on that field NEW value?
Use an SQL monitor to see what is trying to be passed to the server.
Alan