© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•14mo ago
nomodule

Sequence problem with drizzle-seed

I'm experiencing an issue where after seeding data into a PostgreSQL table with Drizzle ORM, the sequence (users_id_seq) doesn't update to reflect the highest id inserted. Here are the details:

Schema:
export const users = pgTable("users", {
  id: serial().primaryKey(),
  // ... other fields
});
export const users = pgTable("users", {
  id: serial().primaryKey(),
  // ... other fields
});


Seeding Script:
async function seedDatabase() {
  await reset(db, schema);
  await seed(db, schema).refine((f) => { 
    // Seeding 10 users without manually setting id
  });
}
async function seedDatabase() {
  await reset(db, schema);
  await seed(db, schema).refine((f) => { 
    // Seeding 10 users without manually setting id
  });
}

Problem: I am not be able to insert 11th user manually. After seeding 10 users,
SELECT last_value, is_called FROM users_id_seq;
SELECT last_value, is_called FROM users_id_seq;
shows last_value as
1
1
, not
10
10
or higher as expected. This causes the duplocated
Id
Id
issue.
Expected Behavior: The sequence should have been updated to the last inserted id after seeding.
Current Workaround: I manually reset the sequence with
SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));
SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));
post-seeding to fix the issue.

Is there a known issue with how Drizzle handles sequences during bulk seeding, or am I missing something in my setup or seeding approach? Any advice or insights would be greatly appreciated.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

drizzle-seed
Drizzle TeamDTDrizzle Team / help
13mo ago
question/problem about new drizzle-seed
Drizzle TeamDTDrizzle Team / help
15mo ago
Drizzle-Seed null values
Drizzle TeamDTDrizzle Team / help
12mo ago
How to refine seed data using `with` clause in drizzle seed
Drizzle TeamDTDrizzle Team / help
8mo ago