Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

MySql: Can't create non-PK column with autoIncrement using createTable changesets

$
0
0
Running the following changeset using liquibase-3.2.2 (on mySql 5.6):
< createTable   tableName = "myTable"   >     
     < column   name = "myId1"   type   =   "BIGINT(20) UNSIGNED"   >     
         < constraints    nullable = "false"   />     
     </ column >  
    < column   name = "myId2"   type   =   "BIGINT(20) UNSIGNED"   >     
         < constraints    nullable = "false"   />     
     </ column >  
       < column   name = "order"     autoIncrement = "true"   type = "BIGINT(20) UNSIGNED"   >     
         < constraints   nullable = "false"   />     
     </ column >     
</ createTable>
< addPrimaryKey   columnNames = "myId1, myId2"   constraintName = "PRIMARY"   tableName = "myTable" />   
< createIndex   indexName = "order_sort_idx"   tableName = "myTable"   unique = "false" >   
     < column   name = "order" />   
</ createIndex >  

will throw the following error during execution: Incorrect table definition; there can be only one auto column and it must be defined as a key

The reason is that liquibase runs each of the elements one at a time. if the <createIndex > would have run with the <createTable> change, the error wouldn't have been thrown.

As a workaround, I create the table using <sql> changeset:
< sql >   
    CREATE TABLE `myTable ` (  
        `myId1` bigint(20) unsigned NOT NULL,  
        `myId2` bigint(20) unsigned NOT NULL,  
        `order` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`myId1`,`myId2`),  
        KEY `order_sort_idx` (`order` ASC)  
    );  
</ sql >   

(also, FYI, I couldn't find a way to open a JIRA ticket in https://liquibase.jira.com/ - it didn't allow me to create a user using any of my email addresses saying my domain is not allowed)

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>