Prisma: Generated starter code has an error when running prisma2 dev for the first time

Created on 17 Jan 2020  ·  3Comments  ·  Source: prisma/prisma

When following the prisma2 init starter wizard and selecting a minimal setup with just the prisma schema, running prisma2 dev for the first time actually complains about syntax errors, which is very surprising for a new user.

Here is the output:

➜  backend git:(master) prisma2 dev
Error: Schema parsing
error: Error parsing attribute "@unique": Fields that are marked as id should not have an additional @unique.
  -->  schema.prisma:13
   |
12 | model User {
13 |   id    String  @default(cuid()) @id @unique
   |
error: Error parsing attribute "@unique": Fields that are marked as id should not have an additional @unique.
  -->  schema.prisma:20
   |
19 | model Post {
20 |   id        String   @default(cuid()) @id @unique

It was easy to fix by simply removing the @unique flags from the schema.prisma file on both id fields.

Original Generated File:

datasource db {
  provider = "postgresql"
  url      = env("POSTGRESQL_URL")
}

generator photon {
  provider = "photonjs"
}

model User {
  id    String  @default(cuid()) @id @unique
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        String   @default(cuid()) @id @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean
  title     String
  content   String?
  author    User?
}

Fix

datasource db {
  provider = "postgresql"
  url      = env("POSTGRESQL_URL")
}

generator photon {
  provider = "photonjs"
}

model User {
  id    String  @default(cuid()) @id
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        String   @default(cuid()) @id
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean
  title     String
  content   String?
  author    User?
}

Most helpful comment

@nikolasburk I'm happy to say that I've finally made the decision to switch over to Prisma 2 for both of my big personal projects, so I'll be trying my best to provide helpful feedback along the way.

I hope this one is helpful.

All 3 comments

@nikolasburk I'm happy to say that I've finally made the decision to switch over to Prisma 2 for both of my big personal projects, so I'll be trying my best to provide helpful feedback along the way.

I hope this one is helpful.

Hi,

Thanks for reporting this! It has already been reported before, so I am going to close this as a duplicate of https://github.com/prisma/prisma2/issues/1223

@pantharshit00 thank you for the quick reply! I tried to look through the existing issues first but must have missed it. I'll try to be more thorough next time to avoid duplicate issues 🙂 Keep up all the great work! 💪🏼

Was this page helpful?
0 / 5 - 0 ratings