简体   繁体   中英

How do I map relationship fields in Prisma?

This is the user model of my current prisma.scheme:

model User{
@@map("users")

ID Int @id @default(autoincrement()) @unique
Firstname String @map("firstname") @db.VarChar(45)
Lastname String @map("lastname") @db.VarChar(45)
Phone String @map("phone") @db.VarChar(60) @unique
EMail String @map("email") @db.VarChar(45) @unique
Username String @map("username") @db.VarChar(45) @unique
Password String @map("password") @db.VarChar(255)
Role Role @map("role") @relation(fields:[Role],references:[ID])
IsLocked Boolean @map("isLocked") @default(false)
Avatar String? @db.VarChar(36) @unique
}

For the "Role" column I get the following error:

Error parsing attribute "@map": The attribute `@map` cannot be used on relation fields.

Is there a way I can map these columns as well?

@map and @@map allow you to name columns and tables differently than what Prisma's default naming convention derives from your field and model names.

You can't use @map for relation fields because they do not end up as columns in your database. Providing a custom name with @map would not make any sense. You can easily confirm this by having a look into your database with Prisma Studio for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM