尝试在H2数据库中创建表时出现Liquibase错误

时间:2015-10-24 17:50:35

标签: plugins gradle h2 liquibase create-table

如何使用Liquibase在H2内存数据库中创建表?我正在使用Gradle 2.7,Liquibase 1.1.1插件和H2 1.4.190插件。这是我的Liquibase创建表语句......

    <changeSet author="davea" id="add_my_prefix_sync_address">
            <createTable tableName="my_prefix_sync_address">
        <column defaultValue="" name="id" type="VARCHAR(32)">
            <constraints nullable="false" primaryKey="true"/>
        </column>
        <column defaultValue="" name="address" type="VARCHAR(500)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="city" type="VARCHAR(100)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="state" type="VARCHAR(10)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="zip" type="VARCHAR(10)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="lattitude" type="INT UNSIGNED">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="longitude" type="INT UNSIGNED">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="email" type="VARCHAR(200)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="phone" type="VARCHAR(32)">
            <constraints nullable="true"/>
        </column>
        <column defaultValue="" name="phone_type" type="VARCHAR(10)">
            <constraints nullable="true"/>
        </column>
            </createTable>
    </changeSet>

但是在运行我的成绩构建命令时,我收到此错误...

Execution failed for task ':update'.
> liquibase.exception.LiquibaseException: Unexpected error running Liquibase: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE PUBLIC.my_prefix_SYNC_ADDRESS (ID VARCHAR(32) DEFAULT '' NOT NULL, ADDRESS VARCHAR(500) DEFAULT '', CITY VARCHAR(100) DEFAULT '', STATE VARCHAR(10) DEFAULT '', ZIP VARCHAR(10) DEFAULT '', LATTITUDE INT UNSIGNED DEFAULT ,[*] LONGITUDE INT UNSIGNED DEFAULT , EMAIL VARCHAR(200) DEFAULT '', PHONE VARCHAR(32) DEFAULT '', PHONE_TYPE VARCHAR(10) DEFAULT '', CONSTRAINT PK_my_prefix_SYNC_ADDRESS PRIMARY KEY (ID)) "; expected "NOT, EXISTS, INTERSECTS, SELECT, FROM"; SQL statement:
  CREATE TABLE PUBLIC.my_prefix_sync_address (id VARCHAR(32) DEFAULT '' NOT NULL, address VARCHAR(500) DEFAULT '', city VARCHAR(100) DEFAULT '', state VARCHAR(10) DEFAULT '', zip VARCHAR(10) DEFAULT '', lattitude INT UNSIGNED DEFAULT , longitude INT UNSIGNED DEFAULT , email VARCHAR(200) DEFAULT '', phone VARCHAR(32) DEFAULT '', phone_type VARCHAR(10) DEFAULT '', CONSTRAINT PK_my_prefix_SYNC_ADDRESS PRIMARY KEY (id)) [42001-190]

如果重要,这些是我在build.grade脚本中设置的插件......

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'mysql:mysql-connector-java:5.1.36'
    classpath 'com.h2database:h2:1.4.190'
    classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
  }
}

…
plugins {
  id "org.liquibase.gradle" version "1.1.1"
}

…

flyway {
    url = 'jdbc:h2:mem:test'
    user = 'sa'
}

liquibase {
  activities {
    main {
      File propsFile = new File(liquibasePropertiesFile)
      Properties properties = new Properties()
      properties.load(new FileInputStream(propsFile))
      changeLogFile 'src/main/resources/db.changelog-master.xml'
      url properties['url']
      username properties['username']
      password properties['password']
    }
    test {
      File propsFile = new File(liquibasePropertiesFile)
      Properties properties = new Properties()
      properties.load(new FileInputStream(propsFile))
      changeLogFile 'src/main/resources/db.changelog-master.xml'
        url 'jdbc:h2:mem:test'
        username 'sa'
    }
    runList = 'main,test'
  }
}

1 个答案:

答案 0 :(得分:0)

将varchar(32)列用作主键可能不合法。