试图在H2数据库中创建表时获得Liquibase错误



如何使用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]

如果重要的话,这些是我在构建中设置的插件。评分脚本…

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'
  }
}

使用varchar(32)列作主键可能是不合法的。

相关内容

  • 没有找到相关文章

最新更新