# Missing FK Constraint bug during addColumn?

**URL:** <https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49>\
**Category:** General Discussion\
**Created:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49 "2009-05-26T20:59:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dynoweb](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dynoweb](https://forum.liquibase.org/u/dynoweb)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/1 "2009-05-26T20:59:00Z")

</div>

I tried to add a couple of new columns with one column as a foreign key to another table and it didn�t create the FK constraint.&nbsp; Am I doing something wrong or is this a bug?

Rick Cromer

Here�s the XML for the change set.

&nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp;

When I run updateSQL or update the creation of the foreign key is not made.&nbsp; Here�s the updateSQL output below:

– Ran at: 5/22/09 10:50 AM  
– Against: POST3@jdbc:oracle:thin:@loghost:1521:ENTICE  
– LiquiBase version: 1.9.1  
– \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
SELECT COUNT(\*) FROM DATABASECHANGELOGLOCK WHERE ID=1;

– Changeset post3Schema.xml::182::cruml::(MD5Sum: fedff0f6941fcc8c1866949687d3fb43)

– Add new columns to the DID\_LOT table

ALTER TABLE DID\_LOT ADD VENDOR\_ID NUMBER(10);

ALTER TABLE DID\_LOT ADD LOAD\_DATE DATE DEFAULT SYSDATE NOT NULL;

INSERT INTO DATABASECHANGELOG (DATEEXECUTED, AUTHOR, LIQUIBASE, DESCRIPTION, COMMENTS, MD5SUM, ID, FILENAME) VALUES (SYSDATE, ‘cruml’, ‘1.9.1’, ‘Add Column’, ‘Add new columns to the DID\_LOT table’, ‘fedff0f6941fcc8c1866949687d3fb43’, ‘182’, ‘post3Schema.xml’);

– Release Database Lock

UPDATE DATABASECHANGELOGLOCK SET LOCKEDBY = NULL, LOCKGRANTED = NULL, LOCKED = 0 WHERE&nbsp; ID = 1;

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/2 "2009-05-26T20:59:00Z")

</div>

I would guess that the addColumn parser is not looking for the foreign key attribute like it should.&nbsp; For now, the best workaround would be to add the column, then use the addForeignKey tag.

Nathan

---

<div class="post-metadata">

**Author:** ![dynoweb](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dynoweb](https://forum.liquibase.org/u/dynoweb)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/3 "2009-05-26T20:59:00Z")

</div>

Should I submit a bug on this or have you already done that?

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/4 "2009-05-26T20:59:00Z")

</div>

I don’t think I did.&nbsp; If you could add it, that would be great.

Thanks,  
Nathan

---

<div class="post-metadata">

**Author:** ![dynoweb](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dynoweb](https://forum.liquibase.org/u/dynoweb)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/5 "2009-05-26T20:59:00Z")

</div>

Added as bug CORE-384.

---

<div class="post-metadata">

**Author:** ![dynoweb](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@dynoweb](https://forum.liquibase.org/u/dynoweb)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/6 "2009-05-26T20:59:00Z")

</div>

Nathan, I attached a fix for this bug based on the 1.9.3 source files.&nbsp; Hope this helps.

Rick Cromer

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 26, 2009, 8:59pm UTC](https://forum.liquibase.org/t/missing-fk-constraint-bug-during-addcolumn/49/7 "2009-05-26T20:59:00Z")

</div>

Great, thanks a lot!&nbsp; I will get it applied.

As a side note, the repository does have write access to anyone with a log in, so you could apply it directly rather than submitting patches if you find that easier.

Either way is perfectly fine with me.

Nathan
