Unique key in PG

Hey guys, sorry I have a little dumb question here 🙂 I wanna know how to set my id field in my PG to auto increament. Here's my schema;
const apiInventory = pgTable("api_inventory", {
id: serial("id").primaryKey(), //I want this to auto-increament.
// other columns and field here...
status: text("status").notNull(),
created_at: timestamp("created_at").defaultNow().notNull(),
last_modified: timestamp("last_modified").defaultNow().notNull(),
});
const apiInventory = pgTable("api_inventory", {
id: serial("id").primaryKey(), //I want this to auto-increament.
// other columns and field here...
status: text("status").notNull(),
created_at: timestamp("created_at").defaultNow().notNull(),
last_modified: timestamp("last_modified").defaultNow().notNull(),
});
Someone look this up please, not sure I've found the right docs yet.
6 Replies
irorochad
irorochadOP5mo ago
This is the message in the console.log
Backend server connected and listening on port 8080
NeonDbError: null value in column "id" of relation "db_name" violates not-null constraint
Backend server connected and listening on port 8080
NeonDbError: null value in column "id" of relation "db_name" violates not-null constraint
rphlmr ⚡
rphlmr ⚡5mo ago
Hum 🧐 what you write is good for me. What is db_name?
irorochad
irorochadOP5mo ago
Sorry for late response, @Raphaël M (@rphlmr) ⚡ The db_name is the actual db name (api_usage).
rphlmr ⚡
rphlmr ⚡5mo ago
Thx. There is a new drizzle orm release: https://github.com/drizzle-team/drizzle-orm/releases/tag/0.32.0 The serial should be replaced with a new thing. Do you think it is worth a try? I will update https://drizzle.run to the latest version but I can’t reproduce this issue (note: it uses an other pg driver and not neon. Maybe it is a neon known issue?)
GitHub
Release 0.32.0 · drizzle-team/drizzle-orm
Release notes for [email protected] and [email protected] It's not mandatory to upgrade both packages, but if you want to use the new features in both queries and migrations, you will need t...
Drizzle Run
Drizzle Run
irorochad
irorochadOP5mo ago
Thank you. I will try the update, and hopefully that should fix it. If it doesn't, I'd assume it's a neon issue.
rphlmr ⚡
rphlmr ⚡5mo ago
take a look at the generated migrations too. Maybe this is an old (or actual) bug of Drizzle kit after a schema change and new migrations I remember cases where some changes where not generated
Want results from more Discord servers?
Add your server