Hi guys I have following Prisma schema: `model Sn...
# orm-help
u
Hi guys I have following Prisma schema:
model Snippet {
id           String      @id @default(uuid())
title        String
user         _User_        @relation(fields: [_userId_], references: [_id_])
userId       String
technology   _Technology_  @relation(fields: [_technologyId_], references: [_id_])
technologyId String
createdAt    DateTime    @default(now())
updatedAt    DateTime    @updatedAt
tags         _Tag_[]
Visibility   _Visibility_? @relation(fields: [_visibilityId_], references: [_id_])
visibilityId String?
}
model Tag {
id        String   @id @default(uuid())
name      String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Snippet   _Snippet_? @relation(fields: [_snippetId_], references: [_id_])
snippetId String?
}
Running
pnpm prisma migrate dev
To update my schema does not add the tags field to my snippet model, what am I missing? Am I creating wrong relation using that syntax, basically a Snippet should be able to contain multiple Tags.
s
The schema is fine and should work as expected. There's no need for tags fields in Snippet table as tags will be fetched based on snippetId.
Copy code
prisma.snippet.findFirst({
 where: {
   id: id
 },
 include: {
    tags: true
 }
})
this should give you snipped along with tags
👀 1
u
hmm what am I missing like it gives a warning
after that I run prisma format
and it gets added again
I get this error, not sure what I may be missing
Error: P3006
`Migration
20220623223220_update_relation_for_snippet_and_tags
failed to apply cleanly to the shadow database.`
Error:
db error: ERROR: foreign key constraint "Snippet_tagId_fkey" cannot be implemented
DETAIL: Key columns "tagId" and "id" are of incompatible types: text[] and text.
0: sql_migration_connector::validate_migrations
at migration-engine/connectors/sql-migration-connector/src/lib.rs:272
1: migration_core::state::DevDiagnostic
at migration-engine/core/src/state.rs:250