Spring Boot does not create the schema on MySQL or PostgreSQL
Tables are created on H2 but not on MySQL or PostgreSQLShort answer
Spring Boot only defaults ddl-auto to create-drop for an embedded database with no Flyway or Liquibase. For MySQL or PostgreSQL it defaults to none, so no tables are created. Set spring.jpa.hibernate.ddl-auto explicitly, or use one schema tool such as Flyway.
Fix it fast
1Find out which cause you have
Search the project for the settings that decide who creates the schema. What you find (or do not find) points to the cause below.
grep -rn "ddl-auto\|sql.init\|flyway\|liquibase" src/main/resources/ pom.xml build.gradle 2>/dev/null2Match what you see, then jump to its fix
- 1
It worked on in-memory H2, and stopped when you switched the URL to MySQL or PostgreSQLddl-auto defaults to none outside embedded databasesFix - 2
A migration tool is in the build, and entities are never turned into tablesFlyway or Liquibase is on the classpathFix - 3
Startup fails in data.sql with a missing table, although ddl-auto is setschema.sql or data.sql runs before Hibernate has created the tablesFix
- 1
What does the error look like?
Tables are created on H2 but not on MySQL or PostgreSQLNo CREATE TABLE statements from Hibernate appear at startup
Cause 1 of 3
ddl-auto defaults to none outside embedded databases
1Check
Spring Boot identifies an embedded database from the connection type and JDBC URL. Only hsqldb, h2 and derby count. For anything else ddl-auto defaults to none.
grep -rn "datasource.url\|ddl-auto" src/main/resources/2Fix
Set the value you want. update is common in development; the docs list none, validate, update, create and create-drop.
spring.jpa.hibernate.ddl-auto=update3Verify
Restart; the tables appear.
mysql -e "SHOW TABLES" appConfirmed by docs.spring.io
Cause 2 of 3
Flyway or Liquibase is on the classpath
1Check
Even on an embedded database, create-drop applies only when no schema manager (Flyway or Liquibase) has been detected. With one present the default is none and your migrations must create the tables.
mvn dependency:tree | grep -i "flyway\|liquibase"2Fix
Put the CREATE TABLE statements in the migrations, and use one mechanism for the schema, not two. The docs advise against mixing several initialization technologies.
-- src/main/resources/db/migration/V1__create_users.sql
CREATE TABLE users (id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL);3Verify
Start the app and list tables.
mysql -e "SHOW TABLES" appConfirmed by docs.spring.io
Cause 3 of 3
schema.sql or data.sql runs before Hibernate has created the tables
1Check
Script-based DataSource initialization runs by default before any JPA EntityManagerFactory is created. By default it also runs only for embedded databases unless spring.sql.init.mode is always.
ls src/main/resources/*.sql2Fix
To let scripts build on what Hibernate creates, defer the script run until after the EntityManagerFactory.
spring.jpa.hibernate.ddl-auto=update
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true3Verify
Restart; scripts run after the tables exist.
mysql -e "SELECT COUNT(*) FROM users" appConfirmed by docs.spring.io
How do I stop it coming back?
- Use none or validate in production and let migrations own the schema.
- Do not assume tables exist when you move from an in-memory to a real database; Spring's docs warn about this.
- Keep one schema mechanism per environment.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Databases
Spring Boot JPA cannot find the PostgreSQL table it maps to
ERROR: relation "telephone_number" does not exist
Spring Boot maps an entity to a lowercase snake_case table name and creates tables on its own only for embedded databases.
2 causes, each with a fixDatabases
Spring Boot fails on startup: HikariPool-1 exception during pool initialization
Caused by: ... (the underlying driver exception)
HikariCP opens one connection when the pool starts, and the startup fails when that connection fails.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Flyway cannot handle the PostgreSQL URL after upgrading to Flyway 10 or newer
No database found to handle jdbc:postgresql://localhost:5432/app
Since Flyway 10, each database has its own module.
4 causes, each with a fixDatabases
H2 in PostgreSQL mode still behaves differently from PostgreSQL
Names or null ordering differ from PostgreSQL in test results
H2 compatibility modes are switched on in the JDBC URL and cover only a small part of the differences between databases.
4 causes, each with a fix