im getting problems with drizzle schemas
Hi everyone, I'm having a problem with the schemas, they all work except for
transportistShema
. If I add this one, I get the error
TypeError: Cannot read properties of undefined (reading 'Symbol(drizzle:Schema)')
if i comment the schema like this, it works and idk why
4 Replies
First, make sure all your schema files are exporting their tables and relations correctly. Looking at your transportist schema file, modify the exports to be explicit
ty for answer, @Yeaba_12 how i should export my schemas?
Make sure to export everything that's needed
export {
trailer,
documentTransportist,
unit,
offer
// ... any other related tables
}
and when importing and using the schema, make sure you're importing all necessary components and some thing like this in another file -> import * as userSchema from './config/schema/users.schema'
import * as giverSchema from './config/schema/cargoGiver.schema'
import * as transportistSchema from './config/schema/transportist.schema'
and if you use node you can make it like this ->>> app.get('/', async c => {
// Destructure and combine schemas explicitly
const schema = {
...userSchema,
...giverSchema,
...transportistSchema,
}
const db = drizzle(c.env.DB, {
schema
})
const res = await db.query.user.findMany({ with: { cargoGiver: true } })
return c.json(res)
})
I have the same issue. My schema is exported correctly because I can use tables in "standard" selects etc.
When I try including any relation in the schema drizzle orm and drizzle studio start failing with this error
I've managed to solve the issue by switching to relative imports from
@/sth
import style