SeaQL / SeaQL/sea-orm

sea-orm-migration will error of the database chartset set utf8mb4

Open
#2,695 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

database SQL Example


CREATE DATABASE ``pay
    DEFAULT CHARACTER SET = 'utf8mb4';

to run:sea-orm-cli migrate

will get an mysql error:Execution Error: error returned from database: 1071,sea-orm

For charset="utf8mb4", we cannot set varchar(255), which should be smaller than 255.

The following is an excerpt from the AI answer

  1. The Cause
    This error occurs when the combined maximum length of the column(s) you're trying to index exceeds the database's limit. This limit is commonly 1000 bytes for InnoDB tables in MySQL/MariaDB, and the length is determined by:

Column length: The maximum size you set (e.g., VARCHAR(255)).

Character set: How many bytes a single character uses. For utf8mb4, a character can take up to 4 bytes.

Composite index: The lengths of all columns in a multi-column index are added together.

For example, a VARCHAR(255) column using utf8mb4 has a maximum length of 255
times4=1020 bytes, which exceeds the 1000-byte limit.

  1. Solutions with SeaORM
    You can fix this by adjusting your entity and migration files to follow one of these strategies:

A. Reduce the Column Length
The most common and easiest solution is to shorten the column's length. For utf8mb4 encoding, a safe length is 191, since 191
times4=764 bytes, which is well below the 1000-byte limit. You'd update your sea_orm entity and migration accordingly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by creating the shown utf8mb4 database and running sea-orm-cli migrate. Then inspect the migration and entity definitions involved in the failing indexed varchar(255) column; done means the migration completes against utf8mb4 without MySQL error 1071.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, rust
Domain
cli, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.