Cannot use prisma migrate dev command after creating view

Viewed 20

i'm trying to create view using migration followed documentation of prisma here I have followed all steps created migration using

npx prisma migrate dev --name create_views --create-only

and copied inside generated create_views\migration.sql

CREATE VIEW "Draft" AS
    SELECT "published", "title", "email", "Post"."id"
    FROM "Post", "User"
    WHERE "published" = false AND "Post"."authorId" = "User"."id";

I successfully created the views but after adding the model manually to schema.prisma

model Draft {
  title     String
  id        Int     @unique
  email     String
  published Boolean
}

I cannot use the command

npx prisma migrate dev

this command will create Draft migration and get failed with message Draft already exists I want to query using prisma on Draft View using prisma inbuilt query and not raw query and also add more tables so npx prisma migrate dev command won't fail

1 Answers

Views in SQL are a kind of virtual table, and they have rows and columns as they are in a real table in the database. so I think you cannot create another table with the name as same in view. you can change your view's name.

Related