Cannot Find Migrations Location in Flyway
Flyway is a popular tool for database migrations. It can be used to create and manage your database schema. However, you may encounter the error "Cannot find migrations location in Flyway" when using Flyway.
Default Location for Migrations
By default, Flyway will look for migrations on the classpath under db/migration
, which in a Maven project means src/main/resources/db/migration
. Ensure that you have a directory like this:
You can refer to the flyway-db-migration-folder Stack Overflow question for more information.
Common Solutions
-
Ensure Correct Directory Structure
Make sure that you have created the
db/migration
directory correctly. Thedb.migration
version will not work because the period (.) in the folder name is hard to spot in some IDEs. -
Specify Migration Locations
You can specify the migration locations explicitly in the
flyway.conf
configuration file. Add the following line:flyway.localtions=filesystem:.
-
Use Double Underscore in Migration File Names
Flyway requires double underscore
__
in the name prefix of migration files. For example,V1__Base_version.sql
instead ofV1_Base_version.sql
. -
Drop or Remove Flyway Schema History Records
If you are getting the "Schema-validation: missing table [table name]" error, you may need to drop the
flyway_schema_history
table or remove the records corresponding to the previous run. -
Use Absolute Path for Migration Locations
If you are on a Mac M1 chip, you may need to use an absolute path instead of a relative path for the migration locations. For example, replace
flyway.localtions=filesystem: relative path
withflyway.localtions=filesystem: absolute path
. -
Ensure Correct Folder Path
Make sure that the folder path in your configuration is correct. Double-check that you are using
db/migration
instead ofdb.migration
. -
Rebuild Module
If all the settings are default, try rebuilding the module.
These are some common solutions to the "Cannot find migrations location in Flyway" error. If you are still encountering problems, you can refer to the Flyway documentation or seek help from the Flyway community.