0
votes

I want to use flywaydb in Kotlin but I have an error in use
My database is PostgreSQL and my ORM is Kotlin Exposed

Code:

val url = "jdbc:postgresql://127.0.0.1/test1"
    Database.connect(url, driver = "org.postgresql.Driver", user = "postgres", password = "123")

    var flyway =  Flyway()
    flyway.setDataSource(url, "postgres", "123")
    flyway.migrate()      

Error:

Exception in thread "main" org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "public" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table. at org.flywaydb.core.Flyway$1.execute(Flyway.java:1197) at org.flywaydb.core.Flyway$1.execute(Flyway.java:1168) at org.flywaydb.core.Flyway.execute(Flyway.java:1655) at org.flywaydb.core.Flyway.migrate(Flyway.java:1168)

How can I solve it? Where is my code wrong?

1

1 Answers

3
votes

Found non-empty schema(s) "public" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.

That error message pretty much says it all. You seem to be running Flyway on a database already populated with tables.

By default, Flyway expects to be run on a brand-new database, in a greenfield project. Flyway installs its own table first, for its internal tracking. This is the “schema history table” mentioned in your error message. After installing its own table, Flyway runs your SQL scripts creating further tables.

If adding Flyway to an existing database, choose either solution:

  • Recreate your database from scratch, starting with an empty database, running Flyway first, then writing and executing SQL scripts to recreate all the elements of your old database, and finally importing existing data.
  • Read about Flyway baseline feature, just as the error message suggested.