Kasir Barati
02/22/2022, 4:34 PMrelation field
?
model Country {
id Int @id @default(autoincrement())
// Country Code Alphabet 3
cca3 String @unique() @db.VarChar(3)
states State[]
capital City? @relation(name: "country_capital")
@@map("countries")
}
model State {
id Int @id @default(autoincrement())
// State Code Alphabet 3
sca3 String @db.VarChar(3)
countryId Int
belongsToCountry Country @relation(fields: [countryId], references: [id], map: "belongs_to_country")
@@index([sca3])
@@map("states")
}
Any thought on this?Adrian
02/22/2022, 6:53 PMAdrian
02/22/2022, 6:55 PMRichard Ward
02/22/2022, 9:37 PMrequired
relationship between State
and `Country`:
belongsToCountry Country @relation(fields: [countryId], references: [id], map: "belongs_to_country")
This means that when you create a State
you need to associate it to a country.Richard Ward
02/22/2022, 9:42 PMcca3
to be in the belongsToCountry
but since you haven;t specified anything at all, it's complaining.