UpdateSQL: Unique Constraints before ForeignKeys

I followed the next steps:

     1. Created with third-party tool a Database Schema in Postgres.

     2. Used Liquibase to export it to an db-initial.xml (changelog) in order to have an start point.

     3. Now deleted the entire database in Postgres.

     4. Created again the database (just Create Database…) empty.

     5. Used Liquibase updateSQL to rebuild it.

What I found:

    1. The Update SQL is generating this SQL

ALTER TABLE public.aisle ADD CONSTRAINT fk_aisle_categories FOREIGN KEY (id) REFERENCES public.aisle_categories (aisle_id) ON UPDATE NO ACTION ON DELETE NO ACTION;

     2. Before this SQL

ALTER TABLE public.aisle_categories ADD CONSTRAINT idx_aisle_categories_1 UNIQUE (aisle_id);

What we have, an ERROR about than there is not Unique restriction in the refered table.

Then I’m not able to persist again my db because the “update” fails when is trying to do this.

¿There is any chance to change it? I mean to force the updateSQL to generate the table his own unique constraints before the foreign keys?

Thank you,


This was my, sorry I was not logged In.

To be more clear: 

Update SQL is generating SQL in this order:

Create tables

Foreign Keys

UniqueConstraints and indexes

I Just moved ForeignKeys block to the end and it works perfect. Why this is not the default behaviour?

It just happened to run in that order. I changed the standard behavior to create the unique constraints first in 3.0.8.


ok, Thank you :slight_smile: