From v1
Upgrading your project from Prisma 1 to Prisma ORM 2 and later
This guide helps you migrate from Prisma 1 to Prisma ORM version 2.x and later.
Prisma 1 was sunset in 2020. This guide is provided for the remaining users who still need to migrate from Prisma 1 to modern Prisma ORM versions.
Main differences between Prisma 1 and Prisma ORM 2+
Prisma ORM 2.x and later versions:
- Don't require hosting a database proxy server (i.e., the Prisma server)
- Make the features of Prisma 1 more modular with dedicated tools:
- Prisma Client: An improved version of Prisma Client 1.0
- Prisma Migrate: Data modeling and migrations (formerly
prisma deploy)
- Use the Prisma schema, a merge of Prisma 1 datamodel and
prisma.yml - Use its own modeling language instead of being based on GraphQL SDL
- Don't expose a GraphQL API for your database—only allow programmatic access via Prisma Client
- Allow connecting to any existing database via more powerful introspection
Upgrade strategies
There are two main upgrade strategies:
-
Upgrade all at once: Entirely remove Prisma 1 from your project and move everything over to Prisma ORM 2+ at once. Recommended for projects not yet in production or with little traffic.
-
Gradual upgrade side-by-side: Add Prisma ORM 2+ to the existing Prisma 1 project and gradually replace existing Prisma 1 features while running them side-by-side. Recommended for high-traffic production applications.
Upgrade path overview
- Install the Prisma ORM 2+ CLI as a development dependency
- Create your Prisma schema and configure the database connection URL
- Use the Prisma CLI to introspect your Prisma 1 database and generate your Prisma schema
- Run the Prisma 1 Upgrade CLI to fix schema incompatibilities
- Install and generate Prisma Client
- Adjust your application code, replacing Prisma Client 1.0 API calls with Prisma Client 2+ API calls
Schema incompatibilities
The database schema created by Prisma 1's prisma deploy is only partially compatible with Prisma ORM 2+. Here's an overview of common incompatibilities:
| Problem | SQL Fix | Prisma Schema Fix | Breaks Prisma 1 |
|---|---|---|---|
| Default values aren't in database | Yes | Yes | No |
| Generated CUIDs as IDs not in database | No | Yes | No |
@createdAt not in database | Yes | Yes | No |
@updatedAt not in database | No | Yes | No |
Inline 1-1 relations missing UNIQUE constraint | Yes | No | No |
| All non-inline relations recognized as m-n | Yes | No | Yes |
Json type is TEXT in database | Yes | No | Varies |
Enums are TEXT in database | Yes | No | Varies |
| Required 1-1 relations not in database | No | Yes | No |
| Mismatching CUID length | Yes | No | No |
| Scalar lists maintained with extra table | Depends | No | Depends |
Using the Prisma 1 Upgrade CLI
The Prisma 1 Upgrade CLI helps you apply workarounds for schema incompatibilities. It generates SQL statements to fix the database schema and make it compatible with Prisma ORM 2+.
Initial setup
- Set up Prisma ORM by installing the CLI and running
npx prisma init - Connect to your database and introspect it with
npx prisma db pull
Fixing schema incompatibilities
- Invoke the Upgrade CLI with
npx prisma-upgrade - Run the generated SQL commands against your database
- Run
prisma db pullagain - Run
npx prisma-upgradeagain - The Upgrade CLI adjusts the Prisma schema by adding missing attributes
The Upgrade CLI is designed so you can stop and restart the process at any time. Once you run a SQL command, it won't show up the next time you invoke the Upgrade CLI.
Upgrading your application layer
After upgrading the Prisma layer, you need to update your application code. Choose the appropriate guide based on your current setup:
- GraphQL Nexus users: Replace the old
nexus-prismaplugin with the newnexus-plugin-prisma - prisma-binding users: Migrate to either Nexus or SDL-first GraphQL
- REST API users: Replace Prisma Client 1.0 calls with Prisma Client 2+ calls
Feature parity notes
Prisma ORM 2+ does not have full feature parity with Prisma 1. The main missing feature is:
- Real-time API (Subscriptions): Prisma ORM 2+ doesn't have built-in database subscriptions. For real-time functionality, consider using native database triggers or triggering GraphQL subscriptions manually inside mutation resolvers.
Getting help
If you encounter issues during migration:
- Check the Prisma 1 Upgrade CLI repository for known issues
- Visit the Prisma Discord for community support
- Open an issue on GitHub for bugs