Drizzle kit migration doesn't reflect schema's relations
I have two schemas in my application, one for parent courses and another one for child courses; they have a one-to-many relation between each other (one parent course can have multiple child courses).
When I run
npx drizzle-kit generate:pg
I see the output in the CLI stating that non of them have foreign keys and when I check the snapshot I verified that no foreign key is present.
My config looks like this:
And both my schemas and their declared relationships are in ./src/schemas/
:
Does anyone knows what I'm doing wrong here?5 Replies
The relations don't automatically create foreign keys for you. It's only the way to tell drizzle what your relations look like
Take a look here: https://orm.drizzle.team/docs/rqb#foreign-keys
Drizzle Queries - DrizzleORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind
ohhhh I get it
so, in order to make a foreign key I must add the
.references()
into the schema right?yup
cool, thanks!