Adding composite unique constraint in Liquibase
I am pretty certain that:
- You can't do it inside the createTable tag itself, but you can do it within the same changeset as when the table is created.
- It does create a composite unique constraint on the two columns. One way you can check is to run liquibase with the command to generate the SQL for update rather than running the update command and check what it does for your database. On the command line, rather than running
liquibase update
you would runliquibase updateSQL
.
You can read liquibase manual also similar problem you can find here
In your case it should be:
<changeSet author="liquibase-docs" id="addUniqueConstraint-example">
<addUniqueConstraint
columnNames="product_id, tournament_id"
constraintName="your_constraint_name"
tableName="person"
/>
</changeSet>