© 2026 Hedgehog Software, LLC

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

Duplicate statements after adding .unique()

Starting from a schema that is entirely synced, I add one
.unique()
.unique()
constraint on one of my columns, then run
drizzle-kit push
drizzle-kit push
and I get the following

 Warning  You are about to execute current statements:

ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        

❯ No, abort
  Yes, I want to execute all statements
 Warning  You are about to execute current statements:

ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        

❯ No, abort
  Yes, I want to execute all statements


This will throw
InvalidArgument desc = Duplicate key name 'MailingList_email_unique' (errno 1061) (sqlstate 42000)
InvalidArgument desc = Duplicate key name 'MailingList_email_unique' (errno 1061) (sqlstate 42000)
when trying to execute the second statement, but it will at least add it.

Now that the key exists, on subsequent calls (without changing anything) it will try to remove it and add it again!

DROP INDEX `MailingList_email_unique` ON ``.`MailingList`;
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);  
DROP INDEX `MailingList_email_unique` ON ``.`MailingList`;
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);        
ALTER TABLE `MailingList` ADD CONSTRAINT `MailingList_email_unique` UNIQUE(`email`);  


I am using
"drizzle-kit": "^0.21.1"
"drizzle-kit": "^0.21.1"
and
"drizzle-orm": "^0.30.10"
"drizzle-orm": "^0.30.10"
and PlanetScale (MySQL).

Any support would be greatly appreciated!

Thank you.
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

Unique statements with `WHERE`
Drizzle TeamDTDrizzle Team / help
7mo ago
Adding unique() to an existing table in Supabase
Drizzle TeamDTDrizzle Team / help
6mo ago
Pkey violates unique constraint after Seed
Drizzle TeamDTDrizzle Team / help
13mo ago
duplicate key value violates unique constraint when trying to insert
Drizzle TeamDTDrizzle Team / help
2y ago