How to fix P1003: Database does not exist in Prisma
The Prisma P1003 error occurs when Prisma cannot find the specified database at the given location. This typically happens due to incorrect database names, connection string issues, or missing database files. The fix involves verifying your database configuration and ensuring the database exists.
Quick fix
Fixes P1003: Database does not exist
-- PostgreSQL
SELECT datname FROM pg_database WHERE datname = 'your_database_name';
-- MySQL
SHOW DATABASES LIKE 'your_database_name';
-- SQL Server
SELECT name FROM sys.databases WHERE name = 'your_database_name';- Verify your DATABASE_URL connection string
- Check if the database exists on the server
- Create the missing database
- Check file paths for SQLite databases
-- PostgreSQLSELECT datname FROM pg_database WHERE datname = 'your_database_name';-- MySQLSHOW DATABASES LIKE 'your_database_name';-- SQL ServerSELECT name FROM sys.databases WHERE name = 'your_database_name';P1003: Database does not exist
What this error means
The P1003 error in Prisma indicates that the database specified in your connection string does not exist at the location Prisma is trying to connect to. This is a connection-level error that occurs before any queries can be executed. For file-based databases like SQLite, the error message will be: "Database {database_file_name} does not exist at {database_file_path}". This means the .db or .sqlite file referenced in your DATABASE_URL doesn't exist at that filesystem location. For server-based databases like PostgreSQL, MySQL, or SQL Server, the error will be: "Database `{database_name}` does not exist on the database server at `{database_host}:{database_port}`" or "Database `{database_name}.{database_schema_name}` does not exist". This indicates that either the database hasn't been created yet, you're connecting to the wrong server, or there's a typo in the database name. This error is part of the P1000-P1017 range of Prisma errors that relate to database connection and configuration issues. It's a critical error because without a valid database connection, your application cannot function.
Typical symptoms
- Prisma Client initialization fails with P1003 error
- Database queries fail immediately with connection errors
- Application startup fails when trying to connect to database
- Error messages mentioning specific database file paths or database names that don't exist
- Migration commands (prisma migrate dev) fail with database connection errors
Common causes
- The database name in your DATABASE_URL environment variable is incorrect or misspelled
- The database file (for SQLite) doesn't exist at the specified path
- The database hasn't been created yet on the database server
- You're connecting to the wrong database server or port
- Special characters or Unicode in database names that aren't properly URL-encoded
- Incorrect schema name specified for databases that use schemas (like PostgreSQL)
How to fix "P1003: Database does not exist"
Check your .env file or environment variables for the DATABASE_URL. Make sure:
- The database name is correct
- The host and port are correct
- For SQLite: the file path exists
- For special characters: they are properly URL-encoded
Example PostgreSQL URL: postgresql://username:password@localhost:5432/mydatabase
Example SQLite URL: file:./dev.db
If using a cloud database, verify you have the correct connection string from your provider.
For server-based databases, connect to your database server using a tool like psql, mysql, or SQL Server Management Studio and verify:
-- PostgreSQL
SELECT datname FROM pg_database WHERE datname = 'your_database_name';
-- MySQL
SHOW DATABASES LIKE 'your_database_name';
-- SQL Server
SELECT name FROM sys.databases WHERE name = 'your_database_name';If the database doesn't exist, you need to create it first.
If the database doesn't exist, create it using your database management tool:
-- PostgreSQL
CREATE DATABASE your_database_name;
-- MySQL
CREATE DATABASE your_database_name;
-- SQL Server
CREATE DATABASE your_database_name;
-- SQLite (file-based)
-- The database file is created automatically when Prisma connectsFor SQLite, ensure the directory path exists and Prisma has write permissions.
For SQLite databases, verify:
1. The file path in your DATABASE_URL is correct
2. The directory containing the .db file exists
3. Your application has read/write permissions to that directory
4. The file isn't locked by another process
Example: If your DATABASE_URL is file:./data/dev.db, make sure the data directory exists in your project root.
You can use absolute paths for more reliability:file:/absolute/path/to/your/project/data/dev.db
Before running your application, test the database connection:
1. For PostgreSQL: psql "postgresql://username:password@localhost:5432/mydatabase"
2. For MySQL: mysql -u username -p -h localhost mydatabase
3. For SQL Server: Use sqlcmd or a GUI tool
4. For SQLite: sqlite3 path/to/your.db (verify the file exists)
If you can't connect manually, the issue is with your database server configuration, not Prisma.
Once the database exists, run Prisma migrations to set up the schema:
npx prisma migrate dev
# or for production
npx prisma migrate deployThis will create the necessary tables and schema in your newly created database.
Advanced notes
Security Note: In Prisma versions before 5.6.0, the P1003 error message could expose your full connection URL including credentials. This was fixed in PR #21805. Always use the latest Prisma version to avoid credential exposure in error logs.
Special Characters in Database Names: Some databases have restrictions on database names. For example:
- Avoid special characters except underscores
- For Unicode/Chinese characters, ensure proper URL encoding
- Some databases are case-sensitive (PostgreSQL), others are not (MySQL on Windows)
Environment-Specific Configuration: In development vs production, you might have different database names. Use environment-specific .env files (.env.development, .env.production) or a configuration management system.
Docker and Containerized Environments: When running in Docker, ensure:
- Database container is running and accessible
- Network configuration allows connection between containers
- Database name matches what's expected in the connection string
- Volumes are properly mounted for SQLite files
Connection Pooling: If using connection pooling (like PgBouncer), ensure it's configured to pass through the correct database name.
Frequently asked questions
- What does "P1003: Database does not exist" mean?
- The P1003 error in Prisma indicates that the database specified in your connection string does not exist at the location Prisma is trying to connect to. This is a connection-level error that occurs before any queries can be executed. For file-based databases like SQLite, the error message will be: "Database {database_file_name} does not exist at {database_file_path}".
- How do I fix "P1003: Database does not exist"?
- The Prisma P1003 error occurs when Prisma cannot find the specified database at the given location. This typically happens due to incorrect database names, connection string issues, or missing database files. The fix involves verifying your database configuration and ensuring the database exists.
- What causes "P1003: Database does not exist"?
- The database name in your DATABASE_URL environment variable is incorrect or misspelled The database file (for SQLite) doesn't exist at the specified path The database hasn't been created yet on the database server
- Is the "P1003: Database does not exist" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Prisma Official Documentation
- ๐prisma.io - error reference(Official Docs)
- ๐prisma.io - error reference(Official Docs)
- ๐github.com - 21805(GitHub)
- ๐github.com - 26886(GitHub)
- ๐github.com - 14421(GitHub)