Found non-empty schema "public" without metadata table! Use init() or set initOnMigrate to true to initialize the metadata table.
- I'm using Postgres 9.2 with Postgis 2.0. This means that by default when I create a new database there will be a table created in
public
schema calledspatial_ref_sys
.
When I run flyway migrate
on this database, I get the above error. Running init
seems to create the public.schema_version
table and mark version 1 as SUCCEDED without actually running the the migration file. I've also tried combinations of initOnMigrate
with no success. Flyway is not configured to manage any schemas.
Any ideas on how I can run a migration in this scenario?
If you are using Gradle you can run
Where public is the name of the database containing the schema_versions table. That should delete the table and metadata as well as running the migrations to get it back up to date.
Caution!
This will delete all data in
public
schemaI think this error comes only with latest version of Flyway i.e. above 4.03. I didn't received in the earlier project but got it when I am using Flyway version 5.07 in my latest project. Putting the code here that resolve my issues
The title is somewhat contradictory, as the database is indeed not virgin as you installed, through the PostGIS extension, a number of objects in the public schema.
You can either
flyway.schemas
to a new schema, say my_app, which will then be created automatically by Flyway. Your application should then use this one instead of public (recommended)flyway.baselineOnMigrate
totrue
or invokeflyway.baseline()
against the public schema. This will work, but public will then contain a mix of both your application objects and the PostGIS objectsthis work for me , i were figthin with the same problema a lot of time
my project was building on maven
next a added this line
next this lines
and i let you the URL of my references from flyway.org Flyway.org/documentation/commandline/baseline
In my case the problem started when I deleted all the rows in the table myschema.schema_version
./gradlew flywayInit
did the trick and the error is not showed anymore.