java – Liquibase试图应用所有变更集,即使数据库存在

前端之家收集整理的这篇文章主要介绍了java – Liquibase试图应用所有变更集,即使数据库存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用 Spring-Liquibase来执行登台数据​​库所需的任何迁移.

applicationContext.xml看起来像

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:component-scan base-package="com.yahoo.comma"/>
    <bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
        <property name="dataSource" ref="dataSource"/>
        <property name="changeLog" value="classpath:liquibase/changelog.xml"/>
        <property name="defaultSchema" value="pryme_dev"/>
    </bean>
</beans>

当我部署war文件时,我看到日志中的错误

INFO 6/11/14 9:32 AM:liquibase: Successfully acquired change log lock
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG
INFO 6/11/14 9:32 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::harith: Reading from pryme_dev.DATABASECHANGELOG
SEVERE 6/11/14 9:32 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::harith: Change Set liquibase/2014/1-1.xml::05192014.1525::harith Failed.  Error: Error executing sql CREATE TABLE pryme_dev.network (id INT NOT NULL,network_id BIGINT UNSIGNED NOT NULL,name VARCHAR(255) NOT NULL,display_name VARCHAR(255) NOT NULL,active TINYINT(1) DEFAULT 1 NOT NULL,created_at TIMESTAMP DEFAULT NOW() NOT NULL,updated_at TIMESTAMP DEFAULT '1970-01-01 00:00:01' NOT NULL,created_by VARCHAR(50) DEFAULT 'pryme_user' NULL,updated_by VARCHAR(50) DEFAULT 'pryme_user' NULL,CONSTRAINT PK_NETWORK PRIMARY KEY (id)): Table 'network' already exists
liquibase.exception.DatabaseException: Error executing sql CREATE TABLE pryme_dev.network (id INT NOT NULL,CONSTRAINT PK_NETWORK PRIMARY KEY (id)): Table 'network' already exists
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:61)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:106)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1189)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1172)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:352)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:40)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:64)
    at liquibase.Liquibase.update(Liquibase.java:202)
    at liquibase.Liquibase.update(Liquibase.java:181)
    at com.yahoo.comma.persistence.DataSetupTest.liquibaseUpdate(DataSetupTest.java:53)
    at com.yahoo.comma.integration.IT1DataSetup.generateDataSet(IT1DataSetup.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: com.MysqL.jdbc.exceptions.jdbc4.MysqLSyntaxErrorException: Table 'network' already exists
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.MysqL.jdbc.Util.handleNewInstance(Util.java:406)
    at com.MysqL.jdbc.Util.getInstance(Util.java:381)
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:1030)
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:956)
    at com.MysqL.jdbc.MysqLIO.checkErrorPacket(MysqLIO.java:3491)
    at com.MysqL.jdbc.MysqLIO.checkErrorPacket(MysqLIO.java:3423)
    at com.MysqL.jdbc.MysqLIO.sendCommand(MysqLIO.java:1936)
    at com.MysqL.jdbc.MysqLIO.sqlQueryDirect(MysqLIO.java:2060)
    at com.MysqL.jdbc.ConnectionImpl.execsql(ConnectionImpl.java:2536)
    at com.MysqL.jdbc.ConnectionImpl.execsql(ConnectionImpl.java:2465)
    at com.MysqL.jdbc.StatementImpl.execute(StatementImpl.java:734)
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:294)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:54)
    ... 44 more
INFO 6/11/14 9:32 AM:liquibase: liquibase/2014/1-1.xml::05192014.1525::harith: Successfully released change log lock
09:32:14.299 [main] DEBUG o.s.t.c.s.DirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@3ba0fcf

问题
– 为什么在已填充数据库并且数据库中存在DATABASECHANGELOG文件时应用所有更改集?
– 我该如何解决这个问题?

谢谢

解决方法

问题通常是因为每个changeSet的唯一标识符的一部分是changelog文件的路径.它看起来像目前被视为“liquibase / 2014 / 1-1.xml”.

如果你运行select * from databasechangelog,其中id =’05192014.1525’数据库中已有的路径是什么?

原文链接:https://www.f2er.com/java/128323.html

猜你在找的Java相关文章