How to Fix MySQL Error 1291 (ER_DUPLICATED_VALUE_IN_TYPE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1291 when an ENUM or SET column has duplicate values. You can fix it by removing the repeated string from your column definition. Database engines check your schema rules before creating or changing a table. When a column list holds the same text twice, the engine stops the change. This check keeps your table rules clean and prevents bad data lookups later. What causes mysql error 1291 in database schemas MySQL uses the symbol ER_DUPLICATED_VALUE_IN_TYPE and SQLSTATE HY00

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 1291 when an ENUM or SET column has duplicate values. You can fix it by removing the repeated string from your column definition.

Database engines check your schema rules before creating or changing a table. When a column list holds the same text twice, the engine stops the change. This check keeps your table rules clean and prevents bad data lookups later.

What causes mysql error 1291 in database schemas

MySQL uses the symbol ER_DUPLICATED_VALUE_IN_TYPE and SQLSTATE HY000 for this specific failure. The message states that a column has a duplicated value in its type list. This problem only affects ENUM and SET column types during table changes.

An ENUM or SET column lets you define a fixed list of allowed strings. Behind the scenes, the database maps each string in the list to a number. If the same string appears twice, the engine cannot map the values well.

Case sensitivity also triggers this error during schema updates. Many tables use character sets that ignore letter case by default. In those tables, the database treats uppercase and lowercase versions as the exact same word.

Extra spaces at the end of a string can also cause this issue. The database often strips trailing spaces when it reads your column list. Two strings that look different because of spaces become identical to the engine.

Automated migration tools often create this error when teams merge code branches. Two developers might add the same status option to a migration file. When the build system runs the script, the database blocks the duplicate value.

How to find and fix duplicate type values

Start by reading the exact error message returned by your database client. The message names the broken column and shows the repeated string value. Open your schema file and search for that column name.

SOC 2 Type I & Type II + Just-in-Time Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Look at all the text values inside the type definition for that column. Remove the extra copy of the value so each option appears only once. Check for words that match when you ignore uppercase and lowercase letters.

If you need both uppercase and lowercase words, change the column collation. A binary collation tells the database to compare the exact byte values of strings. This lets you store both words without triggering a duplicate type error.

Always test your schema changes in a staging database before touching production. Run a check on your migration files during your code review process. This step catches repeated values before your release script runs on live data.

How to run schema changes safely in production

Fixing a broken migration in production carries risk if teams share root credentials. Giving developers full admin rights to fix a table can lead to mistakes. You should limit who can run schema changes on live databases.

Use role-based controls so only approved scripts or leads can alter tables. When an engineer must check a live schema, grant read-only rights first. They can inspect the table rules and character sets without changing live data.

Keep an audit log of every schema change that runs against your database. Require peer approval before anyone runs a fix on a production table. If a query returns sensitive fields, data masking rewrites emails and card numbers in results.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

Does mysql error 1291 mean I have duplicate rows in my table?

No, this error is about the column definition, not the row data. It means the allowed list of ENUM or SET options has a repeated item.

Why do two words with different letter cases trigger this error?

Most default collations in MySQL ignore letter case when comparing text strings. You must use a case-sensitive or binary collation to keep both words.

Can SQL modes bypass the ER_DUPLICATED_VALUE_IN_TYPE check?

Relaxed SQL modes might turn this error into a warning in some setups. Still, you should always remove the duplicate value to avoid index bugs.

The query runs. The emails stay hidden.