AddForeignKeyConstraint Issue

When I add a foreign key constaint on a table, liquibase generates and executes a drop constraint statement before creating the constraint. The liquibase scripts fails when the constaint does not already exist.

I am using db2 expresss.

Any help is appreciated.

Here is the xml i am using:

I’m not sure why it is trying to drop it.  What version of liquibase are you using? 

If you change the tag to be a tag and specify the sql you want it to use, does it work?

Nathan

We are using version 1.9.5. Changing to use the tags will probably resolve my issue.

Let me know if the tag works.  Like I said, I don’t see how the addForeignKeyConstraint tag should be generating teh SQL you are seeing.  Converting to sql would show for sure if the drop statement is created by the addFK tag or something else.

Nathan 

The Sql tag did not work. Unfortunately, dropping schema in db2 is not an easy task. My ideal scenario includes recreating a database from scratch. How can I get past this without running into the drop constraint issue.
Can I add a precondition tag around the addForeignKeyConstraint tag ?

I am using 1.9.5 version.

yes, you should be able to add a precondition to the changeSet to check for the existence of the foreign key.

What is failing with the SQL?  Is it something you could do from the database SQL command line?  The same SQL should work in liquibase.

Nathan