# How do I get the primaryKeyExists preCondition to work?

**URL:** <https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833>\
**Category:** General Discussion\
**Created:** [February 9, 2012, 7:04am UTC](https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833 "2012-02-09T07:04:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljnelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/ljnelson/32/120_2.png) [@ljnelson](https://forum.liquibase.org/u/ljnelson)\
**Post date:** [February 9, 2012, 7:04am UTC](https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833/1 "2012-02-09T07:04:00Z")

</div>

I am attempting to write a preCondition can’t see it for some reason.  
  
Curious if anyone else has experienced it.  
  
Best,  
Laird  
  
–  
[http://about.me/lairdnelson](http://about.me/lairdnelson)

---

<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:** [February 9, 2012, 7:04am UTC](https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833/2 "2012-02-09T07:04:00Z")

</div>

I haven’t seen an issue with the primaryKeyExists check on sqlserver, but I haven’t directly checked it myself for a while. You could always fall back to the precondition as well.

In 2.0 and before the index metadata wasn’t always read as nicely as one would like, so it may be a bug as well.

Nathan

---

<div class="post-metadata">

**Author:** ![ljnelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/ljnelson/32/120_2.png) [@ljnelson](https://forum.liquibase.org/u/ljnelson)\
**Post date:** [February 9, 2012, 7:04am UTC](https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833/3 "2012-02-09T07:04:00Z")

</div>

Found the issue; I’ll let you decide whether it’s a bug or not.  
  
In DATABASECHANGELOG is among the tables, it concludes that it is not.&nbsp; Obviously if the table doesn’t exist, then neither does its primary key.  
  
For now I’ll just do a SQL check and restrict the changeset to run on SQL Server only.  
  
Best,  
Laird  
  
–  
[http://about.me/lairdnelson](http://about.me/lairdnelson)

---

<div class="post-metadata">

**Author:** ![ljnelson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/ljnelson/32/120_2.png) [@ljnelson](https://forum.liquibase.org/u/ljnelson)\
**Post date:** [February 9, 2012, 7:04am UTC](https://forum.liquibase.org/t/how-do-i-get-the-primarykeyexists-precondition-to-work/1833/4 "2012-02-09T07:04:00Z")

</div>

Oh, I should mention as well that of course the primaryKeyExists to also check the Liquibase tables’ primary keys.  
  
Best,  
Laird  
  
–  
[http://about.me/lairdnelson](http://about.me/lairdnelson)
