ip696
ip696

Reputation: 7104

Flyway Found non-empty schema on empty schema

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.

Upvotes: 5

Views: 8013

Answers (3)

MaduKan
MaduKan

Reputation: 700

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

Upvotes: 1

acdcjunior
acdcjunior

Reputation: 135862

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.

Upvotes: 5

N. Labrahmi
N. Labrahmi

Reputation: 667

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.

Upvotes: 2

Related Questions