# Problem getting IndexExists preCondition to work

**URL:** <https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787>\
**Category:** General Discussion\
**Created:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787 "2010-09-07T16:50:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djatnieks](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@djatnieks](https://forum.liquibase.org/u/djatnieks)\
**Post date:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787/1 "2010-09-07T16:50:00Z")

</div>

I am trying to use the “indexExists” precondition tag before dropping an index, and it’s not working - liquibase is always reporting the index does not exist, even though it is present. This causes later changesets to fail because the index was not dropped.

e.g.  
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

I have used version 1.9.5 of Liquibase. Any suggestion what to do differently or how to debug?

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787/2 "2010-09-07T16:50:00Z")

</div>

may be

 ?

to debug your statements are executed, use liquibase updateSQL instead of liquibase update

Cheers, Oleg

---

<div class="post-metadata">

**Author:** ![djatnieks](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@djatnieks](https://forum.liquibase.org/u/djatnieks)\
**Post date:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787/3 "2010-09-07T16:50:00Z")

</div>

Thanks for the suggestions, but as I am using version 1.9.5:  
1: indexExists does not accept “tableName” attribute  
2: updateSQL() is not a method in class Liquibase that I see

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787/4 "2010-09-07T16:50:00Z")

</div>

I just mean commad updateSQL as described in manual. see [http://liquibase.org/manual/command\_line](http://liquibase.org/manual/command_line)

To produce it programatically use

liquibase.update(contexts, getOutputWriter());
generated sql snippets do not send to the server but are wrapping into the output stream. see $LB\_SRC\_195\core\src\java\liquibase\commandline\Main.java:665

---

<div class="post-metadata">

**Author:** ![djatnieks](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@djatnieks](https://forum.liquibase.org/u/djatnieks)\
**Post date:** [September 7, 2010, 4:50pm UTC](https://forum.liquibase.org/t/problem-getting-indexexists-precondition-to-work/787/5 "2010-09-07T16:50:00Z")

</div>

The problem seems to be related to liquibase not recognizing Foreign Key indexes, e.g. the index that I am checking in my is a foreign key index, but liquibase incorrectly determines that the index does not exist.

Looking at SqlDatabaseSnapshot.java, it appears that the readIndexes() method is explicitly removing Primary Key indexes, Foreign Key indexes, and Unique Constraint indexes from the set of indexes. Why? This looks to be the reason that is failing.
