Type mapping with Prisma Migrate

Each Prisma type maps to a default underlying database type - for example, the PostgreSQL maps String to text by default. Native database type attributes specific native type should be created in the database for Prisma types that map to multiple underlying types.

In the following example, the name and title fields have a @db.VarChar(X) type attribute:

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(200)
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String @db.VarChar(150)
published Boolean @default(true)
authorId Int
author User @relation(fields: [authorId], references: [id])
}

Prisma Migrate uses the specified types when it creates a migration:

-- CreateTable
CREATE TABLE "User" (
"id" SERIAL,
"name" VARCHAR(200) NOT NULL,
PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Post" (
"id" SERIAL,
"title" VARCHAR(150) NOT NULL,
"published" BOOLEAN NOT NULL DEFAULT true,
"authorId" INTEGER NOT NULL,
PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Post" ADD FOREIGN KEY("authorId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

Mappings by Prisma type

For type mappings organized by Prisma type, refer to the Prisma schema reference documentation.

Mappings by database provider

For type mappings organized by database provider, see:

Edit this page on GitHub