Schema incompatibilities
Overview
Each section on this page describes a potential problem when upgrading from Prisma 1 to Prisma 2.x and later and explains the available workarounds.
Default values aren't represented in database
Problem
When adding the @default directive in a Prisma 1 datamodel, the default values for this field are generated by the Prisma 1 server at runtime. There's no DEFAULT constraint added to the database column. Because this constraint is not reflected in the database itself, the Prisma 2.x and later versions of introspection can't recognize it.
Example
Prisma 1 datamodel
type Post {
id: ID! @id
published: Boolean @default(value: false)
}
Prisma 1 generated SQL migration
CREATE TABLE "Post" (
id VARCHAR(25) PRIMARY KEY NOT NULL,
published BOOLEAN NOT NULL
);
Result of introspection in Prisma versions 2.x and later
model Post {
id String @id
published Boolean
}
Because the DEFAULT constraint has not been added to the database when mapping the Prisma 1 datamodel to the database with prisma deploy, Prisma v2 (and later versions) doesn't recognize it during introspection.
Workarounds
Manually add a DEFAULT constraint to the database column
You can alter the column to add the DEFAULT constraint as follows:
ALTER TABLE "Post"
ALTER COLUMN published SET DEFAULT false;
ALTER TABLE `Post`
ALTER COLUMN published SET DEFAULT false;
After this adjustment, you can re-introspect your database and the @default attribute will be added to the published field:
model Post {
id String @id
published Boolean @default(false)
}
Manually add a @default attribute to the Prisma model
You can add the @default attribute to the Prisma model:
model Post {
id String
published Boolean @default(false)
}
If the @default attribute is set in the Prisma schema and you run prisma generate, the resulting Prisma Client code will generate the specified default values at runtime (similar to what the Prisma 1 server did in Prisma 1).
Generated CUIDs as ID values aren't represented in database
Problem
Prisma 1 auto-generates ID values as CUIDs for ID fields when they're annotated with the @id directive. These CUIDs are generated by the Prisma 1 server at runtime. Because this behavior is not reflected in the database itself, the introspection in Prisma 2.x and later can't recognize it.
Example
Prisma 1 datamodel
type Post {
id: ID! @id
}
Prisma 1 generated SQL migration
CREATE TABLE "Post" (
id VARCHAR(25) PRIMARY KEY NOT NULL
);
Result of introspection in Prisma versions 2.x and later
model Post {
id String @id
}
Because there's no indication of the CUID behavior in the database, Prisma's introspection doesn't recognize it.