Foreign key issue if comparing against snapshot
ballrod
Posts: 3
It appears that if you rename a primary key, foreign key constraints that are depending on the primary key aren't being included properly in the change script if you are comparing against a snapshot. If you are comparing against another db it is fine (we had to create a db and set it up from the snapshot).
1. Started with:
Table A - Primary key named PK_NOT_RIGHT
Table B - Has a column with a foreign key setup to PK_NOT_RIGHT
2. Create snapshot "Initial"
3. Now, rename the primary key on Table A to PK_TABLE_A
4. Create a change script (update.sql) between the db and snapshot "Initial". You will notice that it isn't dropping the foreign key on Table B.
At this point, if you create a db based on snapshot "Initial" and try running change script update.sql, it will error out when dropping the primary key PK_NOT_RIGHT due to the foreign key dependency on the primary key.
However, if you compare your updated db with the db you created from your "Initial" snapshot, it will correctly recognize the dependency and drop the foreign key constraint prior to dropping PK_NOT_RIGHT.
Let me know if you have any issues reproducing this.
Thanks.
1. Started with:
Table A - Primary key named PK_NOT_RIGHT
Table B - Has a column with a foreign key setup to PK_NOT_RIGHT
2. Create snapshot "Initial"
3. Now, rename the primary key on Table A to PK_TABLE_A
4. Create a change script (update.sql) between the db and snapshot "Initial". You will notice that it isn't dropping the foreign key on Table B.
At this point, if you create a db based on snapshot "Initial" and try running change script update.sql, it will error out when dropping the primary key PK_NOT_RIGHT due to the foreign key dependency on the primary key.
However, if you compare your updated db with the db you created from your "Initial" snapshot, it will correctly recognize the dependency and drop the foreign key constraint prior to dropping PK_NOT_RIGHT.
Let me know if you have any issues reproducing this.
Thanks.
Comments
I'm sorry to say I couldn't duplicate the problem, at least not on version 6.2.0.271. Here is the script that I had used to create the sample database: