P
Prisma5w ago
begot

multi-file schema doesn't work @6.7.0

whenever i run prisma generate i get the following error:
Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Type "RaceEntry" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma\main.prisma:14
|
13 | id String @id @default(cuid())
14 | raceEntries RaceEntry[]
|

Validation Error Count: 1
[Context: getDmmf]

Prisma CLI Version : 6.7.0
Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Type "RaceEntry" is neither a built-in type, nor refers to another model, composite type, or enum.
--> prisma\main.prisma:14
|
13 | id String @id @default(cuid())
14 | raceEntries RaceEntry[]
|

Validation Error Count: 1
[Context: getDmmf]

Prisma CLI Version : 6.7.0
i don't get an error if i remove the Test model from my main.prisma file, but then it doesn't generate any types. and if i run prisma db push no models are added. here's my setup prisma.config.ts
import 'dotenv/config'

import path from 'node:path'

import { defineConfig } from 'prisma/config'

export default defineConfig({
schema: path.join('prisma', 'main.prisma'),
earlyAccess: true,
})
import 'dotenv/config'

import path from 'node:path'

import { defineConfig } from 'prisma/config'

export default defineConfig({
schema: path.join('prisma', 'main.prisma'),
earlyAccess: true,
})
prisma/main.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["queryCompiler", "driverAdapters"]
output = "../client"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Test {
id String @id @default(cuid())
raceEntries RaceEntry[]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["queryCompiler", "driverAdapters"]
output = "../client"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Test {
id String @id @default(cuid())
raceEntries RaceEntry[]
}
prisma/models/races.prisma
model Race {
id String @id @default(cuid())
name String
start DateTime
end DateTime
status String @default("active") // active, completed
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
entries RaceEntry[]
history RaceHistory[]
}

model RaceEntry {
id String @id @default(cuid())
score Int // Stored in milliseconds
position Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
profileId String
profile Profile @relation(fields: [profileId], references: [id])
raceId String
race Race @relation(fields: [raceId], references: [id])

@@unique([profileId, raceId])
}
model Race {
id String @id @default(cuid())
name String
start DateTime
end DateTime
status String @default("active") // active, completed
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
entries RaceEntry[]
history RaceHistory[]
}

model RaceEntry {
id String @id @default(cuid())
score Int // Stored in milliseconds
position Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
profileId String
profile Profile @relation(fields: [profileId], references: [id])
raceId String
race Race @relation(fields: [raceId], references: [id])

@@unique([profileId, raceId])
}
profiles.prisma
model Profile {
id String @id @default(cuid())
displayName String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
raceEntries RaceEntry[]
raceHistory RaceHistory[]
bossEntries BossEntry[]
bossHistory BossHistory[]
}
model Profile {
id String @id @default(cuid())
displayName String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relations
raceEntries RaceEntry[]
raceHistory RaceHistory[]
bossEntries BossEntry[]
bossHistory BossHistory[]
}
i'm importing my generated client for my prisma service.
14 Replies
Prisma AI Help
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurul4w ago
Do you get the same error if you don't use the queryCompiler preview feature?
DevPanda
DevPanda4w ago
Prisma Schema Location and Configuration | Prisma Documentation
Documentation regarding proper location of Prisma Schema including default naming and multiple files.
begot
begotOP4w ago
that's what i was doing. yes, i tried with and without. same thing
Ayoub
Ayoub4w ago
Hi everyone ! Any update on this ? I have the same problem but only in prod for some reason. I already followed the new directory structure and edited my package.json accordingly. Any suggestion ? Well i think i pointed out the problem here
jonfanz
jonfanz4w ago
Are you also using a Prisma config file?
Ayoub
Ayoub4w ago
well no, i tried out but the fact that i need to add dotenv inside my project when using nuxt is a no no for my superior i came back to single prisma schema
jonfanz
jonfanz4w ago
You don’t need to add dotenv. That’s only required if the env vars you need are defined in a .env file. It’s how the ORM loads those values under the hood anyway 🙂 @begot I think your problem is that you’re defining schema in your config as a file instead of a directory
Ayoub
Ayoub4w ago
but the problem was because our prod container do not have the package.json file true, but as we are using docker we do need env so kinda stuck on this
begot
begotOP4w ago
i see, the docs said to define it somewhere, which included the config
jonfanz
jonfanz4w ago
Yep! I meant that you should have a directory there instead of your main.prisma file, if you have multiple prisma files. I think something like this should work:
export default defineConfig({
schema: path.join('prisma'),
earlyAccess: true,
})
export default defineConfig({
schema: path.join('prisma'),
earlyAccess: true,
})
begot
begotOP4w ago
😭 if this works i'm going to be pissed, but thank you, will try now
begot
begotOP4w ago
😅 works like a charm, thank you, i can't believe i missed that @Jon Harrell
No description
jonfanz
jonfanz4w ago
Happy it’s working 🙂 I’ll go ahead and mark this as resolved.

Did you find this page helpful?