Drizzle Studio incompatibility with generatedAlwaysAsIdentity

Basically, https://discord.com/channels/1043890932593987624/1124768693549797416/1279077540266250334 If I define my primary key with .generatedAlwaysAsIdentity(), it seems like I can't add any records in Drizzle Studio because it tries to set the value of the column. This results in an error: cannot insert a non-DEFAULT value into column "id" But I'm 0 days old when it comes to Drizzle, so maybe I'm missing something?
8 Replies
masto
mastoOP2mo ago
Now that I've gone a little further, I'm wondering if it's possible to use identity columns at all. If I define a column as:
id: integer("id").primaryKey().generatedAlwaysAsIdentity()
id: integer("id").primaryKey().generatedAlwaysAsIdentity()
Then I can't even use db.insert(...).values({...}) because the id column is required by Drizzle but forbidden by PostgreSQL. (Unless I do something ugly like id: sql`DEFAULT. This isn't the case with serial, so again I feel like I'm really missing something. Was any support added for identity columns beyond just creating them? Ok, never mind that.. it does work, I was just confused by it being flagged as an error in the "Drizzle runner" editor. But if I execute the line, it runs. Still can't use the actual table editor, though.
masto
mastoOP2mo ago
No description
oke
oke2mo ago
I am using drizzle 0.33.0 and I don't have this error in my Typescript code. Are you using VScode? Can you give code example of your schema
masto
mastoOP2mo ago
If you're talking about the screenshot above, that's from the editor in Drizzle Studio. I think it's a minor issue compared to not being able to use the table editor to add rows, since you can just ignore the error and run the code anyway.
masto
mastoOP2mo ago
Here's a trivial case to reproduce this problem: https://github.com/masto/drizzle-studio-bug
GitHub
GitHub - masto/drizzle-studio-bug
Contribute to masto/drizzle-studio-bug development by creating an account on GitHub.
oke
oke2mo ago
I can confirm this bug exists in Drizzle Kit Studio. Maybe you should raise an issue in the Drizzle Github
masto
mastoOP2mo ago
Thanks. I came here first to double check it was actually a problem because of my limited experience but it's pretty clear it's a thing, so I'll file an issue tomorrow.
masto
mastoOP2mo ago
GitHub
Drizzle Studio can't add records to PG table with generated identit...
If I define my primary key with .generatedAlwaysAsIdentity(), it seems like I can't add any records in Drizzle Studio because it tries to set the value of the column. This results in an error: ...
Want results from more Discord servers?
Add your server