[postgres] composite key does not result in constraint creation
i have this schema, and even though I've got a pretty basic composite primary key, whenever i go into a visual view of my db, no constraint is actually created. with other tables with single column pk's, it creates the constraint like
${tableName}_pkey
, but in this case when i look on Neon there's no constraint here
4 Replies
I've tried to reproduce it and test it with others drizzle-kit versions down to 0.29.0.
This is definitely a bug. Besides your schema, I've tried to reproduce the one, that is provided in the docs (https://orm.drizzle.team/docs/indexes-constraints#composite-primary-key)
and it resulted not in the way as it's supposed to:
(no primary key constraint.)
I will create an issue for that. Thank you for reporting.
In your case, you can modify generated sql, if you use migrations:
or you can just run the following sql saying add me a pk constraint to my table:
Hmmm, I just went to github issues to see if someone already reported it.
https://github.com/drizzle-team/drizzle-orm/issues/3805
In the comments, xorraxraxret suggests providing pk's via array, not via record.
I've tried it on your table:
and it generated right schema:
So you can try doing this.
Anyway, this is still a bug. Docs mention that you can provide a record of constrains, but this doesn't work
GitHub
[BUG]: Composite key ignored when generating migration · Issue #380...
Report hasn't been filed before. I have verified that the bug I'm about to report hasn't been filed before. What version of drizzle-orm are you using? 0.38.2 What version of drizzle-kit...
Cool thanks for the thorough repro and looking into it
I’ll do the aforementioned solution, but yea I agree the docs make it seem like my schema should work
I also agree, I hit this same issue. Definitely feels like a bug considering code verbatim from the docs does not work. Scape's fix above does work, simply removing the object inside of the array and passing the primaryKey straight through the array. The github issue linked above was closed and it is now being tracked here.
https://github.com/drizzle-team/drizzle-orm/issues/3596
GitHub
[BUG]:Composite primary key not added to postgres schema when using...
Report hasn't been filed before. I have verified that the bug I'm about to report hasn't been filed before. What version of drizzle-orm are you using? 0.36.3 What version of drizzle-kit...