Replies: 1 comment
-
|
The unique-constraint parts are right, but heads up on the conflict handling: since you're on mysqlTable, .onConflictDoNothing() and .onConflictDoUpdate() aren't available, those are the Postgres/SQLite methods. MySQL runs ON DUPLICATE KEY UPDATE, so drizzle exposes it as .onDuplicateKeyUpdate(), and there's no target (MySQL works out the conflicting key from the primary/unique indexes itself): // upsert on MySQL There's no direct onConflictDoNothing() for MySQL either, the usual ignore-on-duplicate workaround is to set a column to itself: await db.insert(users) If you ever move this to Postgres or SQLite, that's when onConflictDoUpdate({ target, set }) with an explicit target column comes in. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm looking for what the current workaround is for unique constraints on columns, particularly in MySQL. I can't find any discussions or issues about temporary fixes.
My only idea for how to solve this at the moment is by manually editing the migration files to add constraints before implementing the migration.
Does anyone have a better suggestion that is less prone to human error?
Beta Was this translation helpful? Give feedback.
All reactions