fix error with postgresql

PostgreSQL stores foreign key names in lower case by default, so the precondition was erroneously passing.
Check for the presence of a primary key instead.

This change seems to work with PostgreSQL and the embedded HSQLDB, but I did not try with mySQL or MS SQL Server...