New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation error when creating auto increment column on Mysql #5859
Comments
Hi @jfneis, thank you for reporting this issue. Let me know. |
Hi @tati-qalified! Yes, running validate using Liquibase 4.27.0 via command line the error persists, thus showing that it's not a Spring integration problem.
|
Complementing the possible solution: I found that Mysql allows an auto increment column to be added as a non primary key as long as the new column is a "key" itself. So it will work if:
As an example, all 3 commands below would successfully create an auto increment column in a table that already has a PK:
|
@jfneis I figured out what the problem is - the
It's a simple workaround, though it might get tedious if you need many columns with this configuration. I see that you're willing to submit a PR - our development team is available to provide guidance if needed, so feel free to submit it and ask any questions you may have. Thank you, |
@tati-qalified thanks for pointing out this behavior. The given examples work as there is no validation about column keys when adding an auto increment separately. Actually even not adding the unique constraint, liquibase validates the changeSets and tries to apply them to the database, thus failing with
I'm OK with this exception as liquibase doesn't check the current database characteristics before applying the change sets. Basically, it can't check if the column is not a key in this situation, opposed to when it's adding a new column. All said, the problem remains in the add column statement in a non primary key auto increment column, as liquibase incorrectly doesn't allow a changeSet generated by diffChangeLog to be applied. I will open a PR for this! Thanks for your help! |
Search first
Description
Tried to create an auto increment column with a unique constraint in a mysql table, but Liquibase Validation doesn't allow it with the message "Cannot add a non-primary key identity column".
Despite the validation, coded on this line, mysql actually supports an auto increment column not being a PK, as long as it is a key itself (unique in this case).
Steps To Reproduce
Try to create a an auto increment column with a unique constraint, and it will fail:
Nonetheless, if we run an equivalent SQL command it works:
Expected/Desired Behavior
Expected behavior is that Liquibase Validation allows to create an auto increment column in mysql, even if it's not a primary key, as long as it has a unique constraint associated with it.
Liquibase Version
4.9.1
Database Vendor & Version
mysql 8.2.-0
Liquibase Integration
spring boot
Liquibase Extensions
No response
OS and/or Infrastructure Type/Provider
Ubuntu
Additional Context
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: