schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.6k stars 199 forks source link

"Primary key column cannot equal foreign key column" #65

Closed ercasta closed 8 years ago

ercasta commented 8 years ago

I'm trying to generate a diagram for a schema containing a table whose primary key also has foreign key constraint on it.

Schemacrawler throws an exception complaining that "Primary key column cannot equal foreign key column".

Is there any limitation in Schemacrawler that prevents this configuration to be handled? There is an explicit check in schemacrawler-api/src/main/java/schemacrawler/crawl/BaseColumnReference.java

Regards

schemacrawler commented 8 years ago

Why would a record in a table reference itself? Seems pointless.

ercasta commented 8 years ago

Sorry, you're right. The datamodel I'm looking at is wrong. At first sight, it seemed the columns in the primary key were constrained to reference the primary key of another table, but actually they are referencing themselves. This configuration should anyway be harmless so I agree with your change (70927ec)

schemacrawler commented 8 years ago

Thanks, The only reason you may want to model something like this is to prevent deletes. The best way to do that would be to set appropriate permissions.

ercasta commented 8 years ago

I think it's just a mistake in the datamodel. Most likely the foreign key was intended to refer to another table, to create a table containing additional information for an already existing entity, without changing the original table

schemacrawler commented 8 years ago

Fixed in 14.08.01

schemacrawler commented 8 years ago

Please see #71

schemacrawler commented 8 years ago

I have released SchemaCrawler 14.08.04 with a fix that supports self-referencing foreign keys in database diagrams.