Why {unique:true} doesn't throw?

If I add 3 users with the same email address, it adds them without any issue. How can I make sure the email is unique? I also tried with: email: varchar('email', { length: 256, unique: true, notNull: true }).primaryKey()
const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
email: text('email', { length: 256, unique: true, notNull: true }),
created_at: timestamp('created_at').notNull().defaultNow(),
})
const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
email: text('email', { length: 256, unique: true, notNull: true }),
created_at: timestamp('created_at').notNull().defaultNow(),
})
3 Replies
Asseater Peter
Asseater Peter16mo ago
const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
email: text('email', { length: 256}).unique().notNull(),
created_at: timestamp('created_at').notNull().defaultNow(),
})
const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
email: text('email', { length: 256}).unique().notNull(),
created_at: timestamp('created_at').notNull().defaultNow(),
})
cosbgn
cosbgnOP16mo ago
Great, thanks
Asseater Peter
Asseater Peter16mo ago
Test and let me know, also don't forget to apply this to your database... The fact you wrote this incorrectly doesn't actually matter, since what is throwing the error here is the database and not the ORM btw, don't forget to mark the thread as done for my OCD's sake if this fixed your issue
Want results from more Discord servers?
Add your server