Igorock
Igorock

Reputation: 2901

liquibase.exception.DatabaseException: There is already an object named 'xxxx' in the database

I have a simple createTable changeSet without any additional configurations like this in schema.xml file:

<changeSet author="igor" id="create_test">
    <createTable tableName="test">
        <column name="name" type="varchar(100)">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="value" type="varchar(100)"/>
    </createTable>
</changeSet>

This schema.xml file is included in main changelog.xml file:

<include relativeToChangelogFile="true" file="init/schema.xml" />

When I run liquibase update it works as expected - the table is created. If I run again - it runs successfully and table is not trying to be created again.

But when I run the same code on another server with the same DB credentials - I get exception:

liquibase.exception.DatabaseException: There is already an object named 'test' in the database.

Could you help?

Liquibase version: 3.5.7

DB: Microsoft SQL Server 2016

Similar questions on Stackoverflow are a little bit different and not my case.

Upvotes: 2

Views: 4886

Answers (2)

Igorock
Igorock

Reputation: 2901

I found the reason: relativeToChangelogFile="true" caused this issue. Liquibase checks if changeSet was applied by changeSet name and file name. With relativeToChangelogFile="true" file names are different for different locations of project folder that's why one changeSet was treated as two different on different environments.

Upvotes: 1

bilak
bilak

Reputation: 4932

that means that some object with name test already exists there. You can't have two objects with same name there.

I don't know sqlserver but maybe this select could give you more info:

select * from sys.all_objects where lower(name) = 'test'

You have two options:

  • rename your table from test to something else
  • remove/rename the test object in target database

edit: if it's the same object which you created before, show the liquibase commands which you use for your local setup and for your target db setup.

Upvotes: 1

Related Questions