[Introspection] No @default attribute when introspecting on PostgreSQL from Prisma V1
See original GitHub issueBug description
I am trying to migrate from Prisma1 to Prisma2. When I introspect the database, default values are not generated in the output schema.
How to reproduce
Here is my database schema:
CREATE TABLE "default$default"."User"
(
id character varying(25) COLLATE pg_catalog."default" NOT NULL,
isActive boolean NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY (id)
)
Database schema has no DEFAULT
constraint defined for the column isActive
so it seems logical that there is no @default
attribute in the datamodel after the introspection (Prisma2).
However, it works fine with the Prisma1 introspection where the generated datamodel has the @default
attributes.
The introspected schema:
model User {
id String @id
isActive Boolean
}
Expected behavior
I was expecting the following Prisma2 schema:
model User {
id String @id @default(cuid())
isActive Boolean @default(true)
}
Same behaviour with the @createdAt
and @updatedAt
directives.
Where are defined (or stored) these constraints in the underlying database when using Prisma1 ?
Environment & setup
- OS: Ubuntu 18.04 LTS
- Database: PostgreSQL in Docker (image: postgres:10.3)
- Prisma1 version: prisma@1.34.10
- Prisma2 version: prisma2@2.0.0-preview024
- Node.js version: 8.16.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Schema Incompatibilities | PostgreSQL - Prisma
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...
Read more >Introspection (PostgreSQL) - Prisma 1
IMPORTANT: When introspecting a PostgreSQL database, you're actually introspecting a schema and not a database according to the illustrated model.
Read more >What is introspection? (Reference) - Prisma
Introspection has one main function: Populate your Prisma schema with a data model that reflects the current database schema. Introspect your database with ......
Read more >Upgrading the Prisma layer to Prisma 2 | PostgreSQL
Use the Prisma Upgrade CLI to resolve the schema incompatibilities in the new Prisma 2 data model. Install and generate Prisma Client.
Read more >Introspection | node-postgres - Prisma
Introspect your database with Prisma. For the purpose of this guide, we'll use a demo SQL schema with three tables: CREATE TABLE "public"."User"...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FYI: This will be tackled via https://github.com/prisma/prisma/issues/2499
So it is introspecting the datamodel based on the datamodel… interesting 😉 Thanks for the clarification. We understand the need for a better solution than just P2 introspection and will work on something before GA of P2.