© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
Jorge

Cannot insert rows with drizzle

I have the following schema
export const user = pgTable(
  'User',
  {
    username: varchar('username', { length: 50 }).notNull(),
    password: varchar('password', { length: 255 }).notNull(),
    id: uuid('id').primaryKey().notNull().defaultRandom(),
  },
  (table) => {
    return {
      usernameKey: uniqueIndex('User_username_key').on(table.username),
    }
  },
)
export const user = pgTable(
  'User',
  {
    username: varchar('username', { length: 50 }).notNull(),
    password: varchar('password', { length: 255 }).notNull(),
    id: uuid('id').primaryKey().notNull().defaultRandom(),
  },
  (table) => {
    return {
      usernameKey: uniqueIndex('User_username_key').on(table.username),
    }
  },
)


and I am trying to seed my database with test rows like this
import { db } from './db'
import { user } from './schema'
import { hash } from 'bcrypt'

async function main() {
  try {
    console.log('Seeding database')
    const password = await hash('password', 10)
    const insertedUser = await db
      .insert(user)
      .values({
        username: 'jorge',
        password,
      })
      .returning()
      .execute()
    console.log('Database seeded')
  } catch (e) {
    console.error('Error seeding database', e)
  }
}

;(async () => {
  await main()
})()
import { db } from './db'
import { user } from './schema'
import { hash } from 'bcrypt'

async function main() {
  try {
    console.log('Seeding database')
    const password = await hash('password', 10)
    const insertedUser = await db
      .insert(user)
      .values({
        username: 'jorge',
        password,
      })
      .returning()
      .execute()
    console.log('Database seeded')
  } catch (e) {
    console.error('Error seeding database', e)
  }
}

;(async () => {
  await main()
})()

However, it seems like it does not get past the insert as the "Database seeded" message is never logged in the console. Is there something I am doing wrong?
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

insert multiple rows - onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
2y ago
Insert multiple rows + onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
3y ago
DrizzleORM with JSDoc (insert problem)
Drizzle TeamDTDrizzle Team / help
2y ago
Alias values rows in insert with mysql
Drizzle TeamDTDrizzle Team / help
2y ago