Search code examples
javaswingflyway

Migration of schema PUBLIC to version 1.2 failed


Am writing swing database application in springToolset-eclipse based IDE and maven. so here is my simple db connection code and migrate it with flyway.

Main class

    public static void main(final String[] args) throws SQLException {
        final BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("org.h2.Driver");
        ds.setUrl("jdbc:h2:target/db");
        ds.setUsername("root");
        ds.setPassword("");

        try {
          final Flyway flyway = new Flyway();
          flyway.setDataSource(ds);
          flyway.migrate(); // line no :12
    }}

Schema_name as per flyway(2.2.1) standard is :

V1__init_db.sql

And when i run this code i got this error :

  Exception in thread "main" com.googlecode.flyway.core.api.FlywayException: 
Migration of schema "PUBLIC" to version 1.2 failed! Please restore backups and roll back database and code!
        at com.googlecode.flyway.core.command.DbMigrate.migrate(DbMigrate.java:199)
        at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:872)
        at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:819)
        at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1200)
        at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:819)
        at com.swdb.exApp.Main.main(12)

any one knows what is the error.please help. and also this is a tutoiral from Alber Attard here


Solution

  • Check your database. Flyway has previously run against the configured schema and a migration failed. If you can discard the schema, simply issue flyway.clean() and you should be able to start fresh. IF not, you must perform the cleanup manually before proceeding.