Liquibase - 错误:关系" databasechangelog"已经存在

时间:2014-04-28 07:56:58

标签: liquibase

我正在尝试将liquibase与我们的应用程序集成。我正在使用Maven集成方法执行它。

当我执行时,我看到databasechangelog的创建脚本被调用两次并得到“Table already exists”错误。以下是控制台的声明。我正在使用liquibase-core-3.1.1 jar。

INFO 2014-04-28 06:49:liquibase: Successfully acquired change log lock
INFO 2014-04-28 06:49:liquibase: Creating database history table with name: databasechangelog
INFO 2014-04-28 06:49:liquibase: ChangeSet src/main/resources/sql/postGre/db.changelog-2.0.xml::1::fms ran successfully in 555ms
INFO 2014-04-28 06:49:liquibase: Creating database history table with name: databasechangelog
SEVERE 2014-04-28 06:49:liquibase: Error executing SQL CREATE TABLE databasechangelog (ID VARCHAR(63) NOT NULL, AUTHOR VARCHAR(63) NOT NULL, FILENAME VARCHAR(200) NOT NULL, DATEEXECUTED TIMESTAMP WITH TIME ZONE NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONSTRAINT PK_DATABASECHANGELOG PRIMARY KEY (ID, AUTHOR, FILENAME))
org.postgresql.util.PSQLException: ERROR: relation "databasechangelog" already exists

POM文件条目

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>2.0.1</version>
            <configuration>
                <changeLogFile>src/main/resources/sql/postGre/changelog-master.xml</changeLogFile>
                <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                <defaultschemaName><<my application schema>> </defaultschemaName>
                <driver>org.postgresql.Driver</driver>
                <url>jdbc:<<mydburl>> </url>
                <username>user</username>
                <password>pwd</password>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

请在我出错的地方让我...

4 个答案:

答案 0 :(得分:1)

有了这个工作,我们使用旧版本的posgres,9.1版本接受默认的SchemaName,它现在正在运行。感谢所有的建议。

答案 1 :(得分:1)

对于h2数据库ı存在相同的问题。

我的连接字符串是

  

jdbc:h2:mem:testdb; DB_CLOSE_DELAY = -1; DATABASE_TO_UPPER = false;

从最后删除 DATABASE_TO_UPPER = false 后,它开始工作。

最后一个连接字符串如下:

  

jdbc:h2:mem:testdb; DB_CLOSE_DELAY = -1;

答案 2 :(得分:1)

尝试将 CASE_INSENSITIVE_IDENTIFIERS=TRUE; 参数添加到您的 url 连接。示例:

datasource:
    url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE;

答案 3 :(得分:0)

Mysql数据库中的同一问题,在如下所示的changelog中添加了架构名称后,该问题得以解决。

<changeSet author="chiran" id="Creation of Static Marker">
    <createTable tableName="STATIC_MARKER2" schemaName="SWIFT">
    <column name="marker_id" type="BIGINT" autoIncrement="true">
        <constraints primaryKey="true" nullable="false" />
    </column>
    <column name="marker_name" type="varchar(50)">
        <constraints nullable="false" />
    </column>
    <column name="refillable" type="BIGINT"></column>
    <column name="created" type="TIMESTAMP"/>
    </createTable>
</changeSet>

And below is the snapshot of maven-liquibase plugin version used.
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.6.2</version>