Loading a table into PostgreSQL with a foreign key produces an error
I am using SymmetricDS database replication software to replicate tables
across databases.
I have this XML defined table for PostgreSQL which I've created:
<table name="ServiceItem">
<column name="ServiceItemID" type="INTEGER" required="true"
primaryKey="true"/>
<column name="ParentItemID" type="INTEGER" />
<foreign-key name="FK_ServiceItem_ServiceItem" foreignTable="ServiceItem">
<reference local="ServiceItemID" foreign="ParentItemID" />
</foreign-key>
</table>
I expect that all parentItemID values MUST exist in the ServiceItemID
column, that's the point of a foreign key.
But I get this error from SymmetricDS when I load it:
[] - JdbcSqlTemplate - ERROR: there is no unique constraint matching given
keys
for referenced table "ServiceItem". Failed to execute: ALTER TABLE
"ServiceItem"
ADD CONSTRAINT "FK_ServiceItem_ServiceItem" FOREIGN KEY ("ServiceItemID")
REFERENCES "ServiceItem" ("ParentItemID")
If I remove the foreign key, everything works as expected. This error
message is confusing me and I'm not sure what I am doing wrong. What does
it mean?
No comments:
Post a Comment