Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite @id @default(cuid()) marks field as required #214

Closed
go-viorica opened this issue Jul 22, 2019 · 3 comments
Closed

sqlite @id @default(cuid()) marks field as required #214

go-viorica opened this issue Jul 22, 2019 · 3 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed.
Milestone

Comments

@go-viorica
Copy link

I'm having the following schema:


datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator photon {
  provider = "photonjs"
}


model Comment {
  id         Int      @id @map("i_id")
  internalId String   @id @map("s_id") @default(uuid()) @unique
  text       String   @map("s_text")
  createdAt  DateTime @map("dtu_creation") @default(now())
  updatedAt  DateTime @map("dtu_last_update") @updatedAt

  @@map("tbl_comments")
}

after using prisma2 generate, the generated type will be:

export declare type CommentCreateInput = {
    internalId: string;
    text: string;
};

where internalId is required

@tristancaron
Copy link

I tried with

  internalId                  String?       @map("s_uid") @default(cuid())

It's set to null when I add a new row.

@timsuchanek
Copy link
Contributor

Thanks for reporting @go-viorica! We'll look into it.
@tristancaron that's an unrelated bug, which we will release a fix for soon.

@timsuchanek timsuchanek added the bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. label Jul 23, 2019
@timsuchanek timsuchanek added release/preview6 bug/2-confirmed Bug has been reproduced and confirmed. and removed release/preview5 bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 2, 2019
@mavilein
Copy link
Member

mavilein commented Aug 8, 2019

@go-viorica : Thanks for reporting! 🙏 I noticed that your model has two fields that are marked with @id. This is actually invalid. The id field denotes the primary identifier of a model. Therefore it must have exactly one. I just implemented a validation that rejects this model.
Can you share your reasoning for modeling it this way?
I assume you really needs just one of them so I suggest one of the following:

  1. Remove one of the id fields in your model.
  2. Remove at least @id from one of the fields.

@mavilein mavilein closed this as completed Aug 8, 2019
@janpio janpio added this to the Preview 6 milestone Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed.
Projects
None yet
Development

No branches or pull requests

5 participants