Prisma cannot parse your database connection string. This occurs when your DATABASE_URL has formatting errors, missing components, invalid characters, or incompatible parameters. Common causes include unescaped special characters in passwords, missing database names, and incorrect URL schemes.
The P1013 error indicates that Prisma encountered a malformed or unparseable database connection string. This is a validation error that occurs during the schema parsing phase, before any actual connection attempt. Prisma validates the DATABASE_URL format against strict URL parsing rules. If the URL syntax is invalid, contains unsupported parameters, or lacks required components for your database type, Prisma will reject it with P1013. This error can manifest in several ways depending on what's wrong with your connection string: missing database names (especially MongoDB), unescaped special characters, incorrect URL schemes, empty hosts, or unsupported parameter values.
Ensure your connection string follows the correct format for your database provider:
PostgreSQL/CockroachDB:
DATABASE_URL="postgresql://user:password@localhost:5432/mydatabase?schema=public"
# or
DATABASE_URL="postgres://user:password@localhost:5432/mydatabase?schema=public"MySQL:
DATABASE_URL="mysql://user:password@localhost:3306/mydatabase"MongoDB (requires database name):
DATABASE_URL="mongodb+srv://user:[email protected]/mydatabase?retryWrites=true&w=majority"SQLite:
DATABASE_URL="file:./dev.db"SQL Server:
DATABASE_URL="sqlserver://localhost:1433;database=mydatabase;user=sa;password=Password123;encrypt=true"Check the [Prisma connection URL reference](https://www.prisma.io/docs/orm/reference/connection-urls) for your specific database.
If your password or username contains special characters, they must be percent-encoded:
Common characters to encode:
- @ → %40
- : → %3A
- / → %2F
- ? → %3F
- # → %23
- ! → %21
- $ → %24
- & → %26
Example:
# Original password: p@ssw0rd!
# Encoded: p%40ssw0rd%21
DATABASE_URL="postgresql://user:p%40ssw0rd%21@localhost:5432/mydb"You can use online URL encoders or encode manually. Ensure the encoded string is placed directly in your connection URL without additional quotes or escaping.
Ensure your .env file has no quotes around the connection string:
INCORRECT (will fail):
DATABASE_URL='postgresql://user:pass@localhost:5432/db'
DATABASE_URL="postgresql://user:pass@localhost:5432/db"
DATABASE_URL=`postgresql://user:pass@localhost:5432/db`CORRECT:
DATABASE_URL=postgresql://user:pass@localhost:5432/dbPrisma loads environment variables and parses them without quotes. Adding quotes causes them to be included in the parsed value, breaking URL validation.
Check that the host and port are properly formatted:
Valid host formats:
- localhost (local development)
- 127.0.0.1 (local IP)
- mydb.example.com (domain name)
- db.c.mongodb.net (MongoDB Atlas)
- postgres.railway.app (Railway)
Valid port formats:
- PostgreSQL: 5432 (default)
- MySQL: 3306 (default)
- SQL Server: 1433 (default)
- MongoDB: Included in hostname for Atlas
Example of correct format:
DATABASE_URL="postgresql://user:[email protected]:5432/mydb"If your port contains non-numeric characters, the URL parser will reject it.
Different databases have different requirements:
MongoDB requires database name:
# INCORRECT (no database)
DATABASE_URL="mongodb+srv://user:[email protected]"
# CORRECT (includes /dbname)
DATABASE_URL="mongodb+srv://user:[email protected]/mydatabase"PostgreSQL should include schema parameter:
DATABASE_URL="postgresql://user:pass@localhost:5432/db?schema=public"Parameter values must be correct type:
# INCORRECT (pool_timeout as string)
DATABASE_URL="postgresql://user:pass@localhost:5432/db?pool_timeout=30s"
# CORRECT (pool_timeout as integer)
DATABASE_URL="postgresql://user:pass@localhost:5432/db?pool_timeout=30"Ensure your DATABASE_URL has no extra whitespace:
INCORRECT (has newline):
DATABASE_URL=postgresql://user:pass@localhost:5432/db
?sslmode=requireCORRECT (single line):
DATABASE_URL=postgresql://user:pass@localhost:5432/db?sslmode=requireIf you copy connection strings from multiple lines, ensure you remove all line breaks and extra spaces before using them in your .env file.
Prisma looks for .env files in specific locations:
1. Same directory as package.json
2. The prisma/ directory (if schema.prisma is there)
3. Parent directories (Prisma traverses up the tree)
For development:
# Restart your dev server to reload .env
npm run devFor Prisma CLI commands:
# Explicitly reload environment
npx prisma generate
npx prisma db pushIf you're using Next.js, make sure your variables are in .env.local (not just .env), as Prisma reads from .env by default.
Connection String Validation: Prisma validates the entire connection URL structure before attempting any connection. The validation is strict and follows RFC 3986 URL standards. Even if a connection string looks correct to a human, minor syntax errors will fail validation.
Environment Variable Loading: Prisma uses the dotenv library internally to load .env files. The loading priority is: project root .env > prisma/.env > parent directory .env. If you have multiple .env files at different directory levels, the one closest to your project root takes precedence.
Special Characters in Passwords: Always URL-encode special characters in passwords and usernames. This includes characters that have special meaning in URLs like @, :, /, ?, #, and others. Some tools provide connection string builders that handle this automatically.
Database-Specific Requirements: MongoDB and SQLite have stricter URL requirements than SQL databases. MongoDB requires the database name after the hostname. SQLite uses a file:// scheme. Make sure your provider documentation is consulted for exact format requirements.
Railway and Other Platforms: Cloud providers often provide pre-formatted connection strings. Copy them exactly as provided. Adding, removing, or modifying any part (even seemingly redundant parameters) can cause P1013 errors.
Testing Connection Strings: Before using a connection string in your application, test it with your database provider's CLI tool:
- PostgreSQL: psql <connection-string>
- MySQL: mysql <connection-string>
- MongoDB: mongosh <connection-string>
If the CLI tool can parse it, the format is valid for that database.
P1000: Authentication failed against database server
Authentication failed against database server
P1010: User was denied access on the database
How to fix "P1010: User was denied access on the database" in Prisma
P5008: Usage exceeded, upgrade your plan (Accelerate)
How to fix "Usage exceeded, upgrade your plan" in Prisma Accelerate
P3021: Foreign keys cannot be created on this database
How to fix 'P3021: Foreign keys cannot be created on this database' in Prisma
Value out of range for the type
How to fix 'P2020: Value out of range for the type' in Prisma