# MySQL foreign keys not generating unique indexes as well when required

**URL:** <https://forum.liquibase.org/t/mysql-foreign-keys-not-generating-unique-indexes-as-well-when-required/1066>\
**Category:** General Discussion\
**Created:** [January 17, 2011, 3:41pm UTC](https://forum.liquibase.org/t/mysql-foreign-keys-not-generating-unique-indexes-as-well-when-required/1066 "2011-01-17T15:41:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scryan7371](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@scryan7371](https://forum.liquibase.org/u/scryan7371)\
**Post date:** [January 17, 2011, 3:41pm UTC](https://forum.liquibase.org/t/mysql-foreign-keys-not-generating-unique-indexes-as-well-when-required/1066/1 "2011-01-17T15:41:00Z")

</div>

I tried to generate a change log to match my existing database.&nbsp; Some of my foreign keys are also unique indexes and some have RESTRICT on the ondelete and onupdate.&nbsp; The generated change log did not also generate the unique index when required.&nbsp; I see an attribute that gets generated called referencesUniqueColumn and it is set to false.&nbsp; When I set it to true I get an error that the addForeignKeyConstraint is not supported on mysql but when I set it to false at least is tries to generate a foreign key.

Here is what is generated

&nbsp; &nbsp; &nbsp; &nbsp; \<addForeignKeyConstraint baseColumnNames=“creator\_id” baseTableName=“audience”&nbsp; constraintName=“FK3A26EA04CE7B13AF” deferrable=“false” initiallyDeferred=“false” onDelete=“NO ACTION” onUpdate=“NO ACTION” referencedColumnNames=“id” referencedTableName=“app\_user”&nbsp; referencesUniqueColumn=“false”/\>

I can supply more information if required or a work around would be appreciated.&nbsp;

---

<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:** [January 17, 2011, 3:41pm UTC](https://forum.liquibase.org/t/mysql-foreign-keys-not-generating-unique-indexes-as-well-when-required/1066/2 "2011-01-17T15:41:00Z")

</div>

The diff support doesn’t always handle indexes the best.&nbsp; It is planned to be the focus of 2.1.&nbsp; If you could give the original create table SQL for comparison, that would help.

Nathan
