Author Topic: Cannot change the PK selection columns in a table when FK exist  (Read 6168 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1370
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Cannot change the PK selection columns in a table when FK exist
« on: November 07, 2022, 08:09:29 pm »
Hi,

I have a data model generated via a DB reverse that is updated in EA in order to provide details of the changes to be made by the DBA for the next release.
I have a table with 2 columns selected as PK (e.g. table1 with id1 [PK], id2 [PK], name), and tables linked to this table via foreign keys (e.g. table2 with id [PK], tbl1id1 [FK], tbl1id2 [FK]).
I need to add a new column in the primary keys selection (e.g. id3), however this generates the following error: Cannot change the involved columns of a constraint that is part of a foreign key relationship.

I tried to change the existing PK constraint or add one with the new column, but it's not possible.
The only solution involves deleting the FK associations to this table, set the new column as a PK, and recreate the associations. This method requires deleting and generating new operations which is not ideal.

Is there a workaround ? A script could probably help to automatically update all FK operations and avoid deleting anything, but it won't be an easy one.
Note that I found a thread on this topic here, but the link to another thread doesn't work: https://sparxsystems.com/forums/smf/index.php?topic=8302.0

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Cannot change the PK selection columns in a table when FK exist
« Reply #1 on: November 07, 2022, 08:24:29 pm »
That's likely because they once had a crash that made them setup a new forum. Maybe Paolo remembers (at least I remember those times when David was aboard). Probably the scripting isn't too difficult, but I'm absolutely not in that DB stuff so can't do any test on the fly.

q.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: Cannot change the PK selection columns in a table when FK exist
« Reply #2 on: November 08, 2022, 08:30:52 am »
That's likely because they once had a crash that made them setup a new forum.


Not quite. We changed the forum software (from YaBB to smf) because the search feature was painfully slow. All the old posts were copied over, but their links changed. If you come across any old YaBB links, do a search for the text in its title and you should be able to find it, e.g. the post that Guillaume mentioned is BAD: [  ] Unique - totally defective
The Sparx Team
[email protected]

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1370
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Cannot change the PK selection columns in a table when FK exist
« Reply #3 on: November 08, 2022, 06:53:28 pm »
Thank you for the link to the old forum post.
About my initial question, I'm looking at the way to update the PK and FK constraints via a script when a column PK property is enabled, but the column is not yet in the PK constraint (applicable for compound primary keys).
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Cannot change the PK selection columns in a table when FK exist
« Reply #4 on: November 08, 2022, 11:13:23 pm »
Very faint remembering about  t_operationtag?! Otherwise look into the famous t_xref...

q.

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1370
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Cannot change the PK selection columns in a table when FK exist
« Reply #5 on: November 09, 2022, 09:43:24 pm »
I managed to get a script working by looking at the table PK operations to add the new PK column as a new parameter, and use the FK associations to update the FK operations on the associated tables (create or add the matching FK attribute).

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com