Liquibase简单更改日志NullPointerException

时间:2018-01-27 18:52:58

标签: liquibase

我使用Liquibase进行了简单的迁移设置。不幸的是,当我尝试addColumn时,它会导致NullPointerException。 (创建表工作正常)。

// File structure
pom.xml
  src/main/resources/liquibase/
    db.changelog.xml
    liquibase.properties
    changesets/
      simple.changeset.xml


// pom.xml
<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>${liquibase.version}</version>
    <configuration>
        <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
        <changeLogFile>src/main/resources/liquibase/db.changelog.xml</changeLogFile>
        <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
    </configuration>
</plugin>

// simple.changeset.xml
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
     http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">
    <changeSet id="1517019028" author="me">
        <createTable tableName="test">
            <column name="test_field_1" type="varchar(255)"></column>
        </createTable>
        <addColumn tableName="test">
            <column name="test_field_2" type="varchar(255)"></column>
        </addColumn>
    </changeSet>
</databaseChangeLog>

createTable命令成功,但addColumn命令总是失败。运行mvn clean package liquibase:update会生成以下错误:

java.lang.NullPointerException
    at liquibase.structure.core.Index.setColumns(Index.java:100)
    at liquibase.snapshot.jvm.PrimaryKeySnapshotGenerator.snapshotObject(PrimaryKeySnapshotGenerator.java:65)
    at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:60)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:194)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:272)
    at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:234)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:208)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:292)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:314)
    at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:234)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:208)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:272)
    at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:234)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:208)
    at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:70)
    at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:44)
    at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:21)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:150)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:158)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:154)
    at liquibase.database.core.SQLiteDatabase.getAlterTableStatements(SQLiteDatabase.java:133)
    at liquibase.sqlgenerator.core.AddColumnGeneratorSQLite.generateSql(AddColumnGeneratorSQLite.java:67)
    at liquibase.sqlgenerator.core.AddColumnGeneratorSQLite.generateSql(AddColumnGeneratorSQLite.java:19)
    at liquibase.sqlgenerator.SqlGeneratorChain.generateSql(SqlGeneratorChain.java:30)
    at liquibase.sqlgenerator.SqlGeneratorFactory.generateSql(SqlGeneratorFactory.java:216)
    at liquibase.executor.AbstractExecutor.applyVisitors(AbstractExecutor.java:25)
    at liquibase.executor.jvm.JdbcExecutor.access$500(JdbcExecutor.java:36)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:289)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:107)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1251)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1234)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:554)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)
    at liquibase.Liquibase.update(Liquibase.java:212)
    at liquibase.Liquibase.update(Liquibase.java:192)
    at liquibase.Liquibase.update(Liquibase.java:327)
    at org.liquibase.maven.plugins.LiquibaseUpdate.doUpdate(LiquibaseUpdate.java:33)
    at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask(AbstractLiquibaseUpdateMojo.java:30)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:394)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

之前有人遇到过这个问题吗?从我从文档中可以看出,我的设置相当典型但我在网上找不到任何类似的问题。

以下是我为展示问题而创建的示例回购:https://github.com/cha55son/liquibase-add-column-bug

1 个答案:

答案 0 :(得分:0)

这可能是针对SQLite的liquibase驱动程序的错误。

https://liquibase.jira.com/browse/CORE-2468

如果是这种情况,您可能希望切换到另一个数据库。

或者,您可以尝试在更改集中使用原始SQL(基于您的github代码):

    <changeSet id="2" author="me">
        <sql>
            ALTER TABLE TEST ADD COLUMN TEST_FIELD varchar(255)
        </sql>
    </changeSet>