1
votes

I am getting a "table already exists" error from Liquibase when I run my Jhipster project:

[ERROR] liquibase - classpath:config/liquibase/master.xml: classpath:config/liquibase/changelog/db-changelog-001.xml::1::jhipster: Change Set classpath:config/liquibase/changelog/db-changelog-001.xml::1::jhipster failed.  Error: Error executing SQL CREATE TABLE fc.T_USER (login VARCHAR(50) NOT NULL, .....: Table 't_user' already exists

I have generated the Liquibase changelog file into config\liquibase\changelog directory using

liquibase --driver=com.mysql.jdbc.Driver ^
      --classpath=C:\Users\Greg\.IntelliJIdea13\config\jdbc-drivers\mysql-connector-java-5.1.31-bin.jar ^
      --changeLogFile=db-changelog-001.xml ^
      --url="jdbc:mysql://localhost/fc" ^
      --username=root ^
      generateChangeLog

So something is tricking Liquibase into trying to re-create the database when the changelog, I thought, was setting a baseline of the existing database.

  • Jhipster version: When I yo jhipster -v is says 1.2. When I nmp update jhipster is says I am on the latest = 17.2
  • Liquibase version tried 3.0, 3.1 and 3.2
  • Mysql database from XAMP
  • 2 tables are created in Mysql - databasechangelog and databasechangeloglock
  • databasechangelog remains empty and databasechangeloglock has a record added when Jhipster app is run

This process was working but not since move to new computer. When it was working I saw databasechangelog had a couple of records in it as well as 1 in databasechangeloglock

Tips on how to debug as welcome as an answer. Thanks.

1
Explained in the documentation. You need to run the "changeLogSync" command to indicate that the changesets (specifically the one creating the table) should be marked as applied. See: liquibase.org/documentation/existing_project.htmlMark O'Connor
ok, I see that is a documented step. When I run changeLogSync it populates databasechangelog table with what looks like correct rows.Ribeye
Unfortunately liquibase still throws the "table already exists" error. So I put in the <preconditions onFail="MARK_RAN"> which stops the error. I remove the <preconditions onFail="MARK_RAN"> and the error does not come back. Also, my other Jhipster projects did not have changeLogSync run and they worked fine. (I reverted to liquibase 3.0 because I think I see Jhipster has this hard coded as the xsd version). What could be going on?Ribeye

1 Answers

1
votes

Running generateChangeLog as described above, and then changeLogSync in situ, results in the field [FILENAME] in the databasechangelog table having the value db-changelog-001.xml.

What it needs to be is the full address from where liquibase is run. When in a Jhipster app I am seeing classpath:config/liquibase/changelog/db-changelog-001.xml. So it does not seem to be using only ID as the row identifier, as I was expecting.