AlexSPx
06/14/2021, 4:17 PMmodel User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String @unique
username String @unique @db.VarChar(255)
name String
password String
teams Team[]
@@map("user")
}
model Team {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @unique
displayName String
description String @db.VarChar(500)
membersId String[] @db.Uuid
adminsID String[]
members User[] @relation(fields: [membersId], references: [id])
@@map("team")
}
I've tried a few other things to do it, but every time I get this error Key columns "membersId" and "id" are of incompatible types: uuid[] and uuid.
Any help would be appreciated.Joey
06/14/2021, 4:58 PMarray of uuid's while the other is just one uuidJoey
06/14/2021, 4:59 PMexplicit many-to-many relationship. For this you’d need to define an additional modelJoey
06/14/2021, 5:00 PMAlexSPx
06/14/2021, 5:23 PMSamrith Shankar
06/14/2021, 5:24 PMmodel User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String @unique
username String @unique @db.VarChar(255)
name String
password String
teams Team[]
@@map("user")
}
model Team {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @unique
displayName String
description String @db.VarChar(500)
adminsID String
members User[]
@@map("team")
}
Try this outSamrith Shankar
06/14/2021, 5:26 PMAlexSPx
06/14/2021, 5:35 PMAlexSPx
06/14/2021, 5:47 PMError: P3006
Migration `20210614155639_init` failed to apply cleanly to the shadow database.
Error:
Database error
Error querying the database: db error: ERROR: foreign key constraint "team_membersId_fkey" cannot be implemented
DETAIL: Key columns "membersId" and "id" are of incompatible types: uuid[] and uuid.
0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
at migration-engine\connectors\sql-migration-connector\src\flavour\<http://postgres.rs:280|postgres.rs:280>
1: sql_migration_connector::sql_database_migration_inferrer::validate_migrations
at migration-engine\connectors\sql-migration-connector\src\<http://sql_database_migration_inferrer.rs:88|sql_database_migration_inferrer.rs:88>
2: migration_core::api::DevDiagnostic
at migration-engine\core\src\<http://api.rs:95|api.rs:95>jasci
06/14/2021, 5:47 PMteams field isn’t gonna be in the User table as well as members in the Team table. Those are relation(virtual) fields, relation between these models are stored in the separate table(JOIN), you won’t need to worry about it. With prisma client you are able to query those fields even though they are technically absent in the table like this:
prisma.team.findUnique({ where: { name: 'some name' }).members() and it will return all members records that are “stored” in the Team table.AlexSPx
06/14/2021, 5:50 PMjasci
06/14/2021, 5:52 PM@db.Uuid ?
membersId String[] @db.Uuid
->
membersId String[]
?jasci
06/14/2021, 5:53 PMnpx prisma migrate dev command ?jasci
06/14/2021, 5:53 PMAlexSPx
06/14/2021, 5:54 PMAlexSPx
06/14/2021, 5:55 PMmembers User[]jasci
06/14/2021, 5:56 PMAlexSPx
06/14/2021, 5:56 PMjasci
06/14/2021, 5:57 PMThis error occur aftercommand ?npx prisma migrate dev
AlexSPx
06/14/2021, 5:58 PMjasci
06/14/2021, 6:00 PMAlexSPx
06/14/2021, 6:09 PMnpx prisma db push seems to work, It pushed the changesjasci
06/14/2021, 6:13 PMdb push and migrate dev interchangeably (choose one for your needs)
https://www.prisma.io/docs/concepts/components/prisma-migrate/db-push#choosing-db-push-or-prisma-migrateAlexSPx
06/14/2021, 6:19 PMSamrith Shankar
06/14/2021, 7:49 PMdb push was my second suggestion. But like @jasci mentioned, it is not good practise to merge db push and migrate. One is for dev another for prod