Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No database found to handle error with flyway postgresql

I am new to Java, trying to setup a first API.

I have a Springboot app which connects to a postgresql database on a docker container.

I do manage to access the database from the app, so the database in on and accessible as per my application.properties:

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/portfolio
spring.datasource.username=postgres
spring.datasource.password=123456
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

spring.jpa.hibernate.ddl-auto=none

When attempting to setup migrations with flyway with the command:

mvn flyway:migrate

I get the error:

No database found to handle jdbc:postgresql://localhost:5433/portfolio

This is how the pom.xml for flyway looks like:

            <plugin>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>10.7.1</version>
            <configuration>
                <sqlMigrationSeparator>__</sqlMigrationSeparator>
                <locations>
                    <location>filesystem:src/main/resources/db/migration/portfolio</location>
                </locations>
                <url>jdbc:postgresql://localhost:5433/portfolio</url>
                <user>postgres</user>
                <password>123456</password>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.flywaydb</groupId>
                    <artifactId>flyway-core</artifactId>
                    <version>10.7.1</version>
                </dependency>
            </dependencies>
        </plugin>

EDIT - adding docker-compose as requested

version: "3.8"
volumes:
  db:
services:
  postgresdb:
    container_name: postgres_container
    image: postgres
    restart: unless-stopped
    env_file: ./.env
    environment:
        - POSTGRES_USER=$POSTGRESDB_USER
        - POSTGRES_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
        - POSTGRES_DB=$POSTGRESDB_DATABASE
    ports:
        - $POSTGRESDB_LOCAL_PORT:$POSTGRESDB_DOCKER_PORT
    volumes:
        - db:/var/lib/postgres
  pgadmin:
    image: dpage/pgadmin4:latest
    environment:
        PGADMIN_DEFAULT_EMAIL: [email protected]
        PGADMIN_DEFAULT_PASSWORD: admin
        PGADMIN_LISTEN_PORT: 5050
    ports:
        - '5050:5050'

.env file

POSTGRESDB_USER=postgres
POSTGRESDB_ROOT_PASSWORD=123456
POSTGRESDB_DATABASE=portfolio
POSTGRESDB_LOCAL_PORT=5433
POSTGRESDB_DOCKER_PORT=5432
like image 599
BernardA Avatar asked Oct 29 '25 02:10

BernardA


1 Answers

The error says No database found to handle jdbc:postgresql. This doesn't mean that the database is not accessible/running, but that Flyway can't handle the PostgreSQL database type. You should add this to the Maven Plugin dependencies:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <version>11.3.4</version>
</dependency>

Please note: latest Flyway version is 11.3.4

Based on: https://github.com/flyway/flyway/issues/3722

like image 79
Mar-Z Avatar answered Oct 31 '25 16:10

Mar-Z



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!