4
votes

I am trying to implement DB migration with Flyway 4.2.0 + Oracle 11g

I have this empty schema:

schema with no tables

And when I try to migrate, Flyway says:

Caused by: org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "PASHA" without metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.

This is the config:

@Bean(initMethod = "migrate")
Flyway flyway() {
    Flyway flyway = new Flyway();
    flyway.setBaselineOnMigrate(false);
    flyway.setSchemas("PASHA");
    flyway.setLocations("classpath:db/migration/oracle");
    flyway.setDataSource("jdbc:oracle:thin:@host:1521:test", "login", "password");
    return flyway;
}

Why do I get this message? My base is empty.

3

3 Answers

3
votes

Flyway itself uses a query to check if the schema is empty.

In the case of oracle, the query is:

SELECT * FROM ALL_OBJECTS WHERE OWNER = ?

Execute that query (with your owner in the place of ?) and see if it returns something (it does).


For instance, LOBs that haven't been purged show there. If that's the case, try:

purge recyclebin;

and the query should be empty now.

2
votes

You need to either let Flyway create the schema itself (meaning there should not be a 'PASHA' schema created before hand), or baseline the existing schema (meaning setting your configuration with flyway.setBaselineOnMigrate(true) ).

Basically, Flyway tries to create a schema ('PASHA' in your example) which already exists.

1
votes

Adding all of these helped. But the one without spring actually did the trick! Silly as it is, but just worked!

spring.flyway.baselineOnMigrate=true
spring.flyway.baseline-on-migrate = true
flyway.baseline-on-migrate= true
flyway.baselineOnMigrate=true