Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase not working with mysql autoincrement

I try to create a new table via a liquibase changeset that looks like:

    <createTable tableName="mytable">
        <column name="id" type="number" autoIncrement="true">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="name" type="varchar(50)"/>
        <column name="description" type="varchar(255)"/>
        <column name="image_path" type="varchar(255)"/>
    </createTable>

this fails with following error:

liquibase.exception.DatabaseException: 
Error executing SQL CREATE TABLE 
kkm.mytable (id numeric AUTO_INCREMENT NOT NULL, name VARCHAR(50) NULL, description 
             VARCHAR(255) NULL, image_path VARCHAR(255) NULL, 
             CONSTRAINT PK_BOUFFE PRIMARY KEY (id)): 
Incorrect column specifier for column 'id'

if I set autoIncrement="false", this works perfectly.
Is this a known issue ?

EDIT:

this is working:

    <createTable tableName="mytable">
        <column name="id" type="number" autoIncrement="false">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="name" type="varchar(50)"/>
        <column name="description" type="varchar(255)"/>
        <column name="image_path" type="varchar(255)"/>
    </createTable>

    <addAutoIncrement
            columnDataType="int"
            columnName="id"
            incrementBy="1"
            startWith="1"
            tableName="mytable"/>
like image 851
Frederic Close Avatar asked Dec 09 '13 14:12

Frederic Close


1 Answers

Change type="number" to type="BIGINT".

i,e

 <createTable tableName="mytable">
        <column name="id" type="BIGINT" autoIncrement="true">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="name" type="varchar(50)"/>
        <column name="description" type="varchar(255)"/>
        <column name="image_path" type="varchar(255)"/>
    </createTable>

Hope it works..!!!!

like image 115
Waheed Avatar answered Oct 13 '22 23:10

Waheed