Generate an initial Prisma schema
Adopting Prisma for an existing relational database.
Prisma · Command
prisma db pull introspects a database and updates the Prisma schema with models matching its current structure. It reads the connection configuration from Prisma config and supports options for selecting, printing, or replacing schema output.
The command reads the datasource connection from Prisma configuration, connects to the database, inspects its structure, converts that structure into Prisma schema models, and writes the result to the schema file. Use options to select a different schema or URL, print instead of write, or disregard the existing schema.
prisma db pull [options]| Name | Type | Description |
|---|---|---|
options | object | Optional command flags such as --force, --print, --config, --schema, --url, --schemas, and connector-specific options. |
Writes the introspected Prisma schema to the configured or selected schema file, or prints it to stdout when --print is used.
prisma.config.ts before running the command.--force when the introspected database should completely replace the existing schema model.--print to inspect generated schema output without directing it to the schema file.--schemas selects which database schemas to inspect.prisma db pull --schema=./prisma/schema.prismaIntrospects the configured database and writes the resulting Prisma schema to the specified schema file.
Adopting Prisma for an existing relational database.
A database was changed with SQL or another migration system.
You need to inspect generated schema without modifying the file.
A project uses multiple database schemas.
prisma db pull do?It connects to the configured database, introspects its current structure, converts that structure into Prisma models, and writes the result to the Prisma schema. The datasource URL comes from the Prisma config file.
Follow-up: How would you intentionally discard existing schema customizations? Use --force, which makes the generated schema solely from introspection and ignores the existing Prisma schema.
The command can merge database changes with an existing relational Prisma schema, but it may overwrite the schema file. Important manual changes should therefore be committed or backed up before running it.
Follow-up: What should follow a successful pull in an application using Prisma Client? Run prisma generate so the client reflects the updated schema.
The basic syntax is prisma db pull [options]. Useful options include --print to send the introspected schema to standard output, --force to ignore the current schema, and --schema to choose another schema path.
Follow-up: How can the connection target be changed without editing the config? Supply --url to override the datasource URL from the Prisma config.
prisma generateprisma db pushprisma db executeprisma.config.ts--force--print--schema--url