Expand description
MySQL / MariaDB DDL (MySQL 8.0.31+).
The editor mirrors the PostgreSQL one in super, with the dialect
differences MySQL forces on a schema tool:
- Quoting. Identifiers use backticks (embedded backticks doubled).
String literals escape backslashes as well as quotes, because MySQL
treats
\as an escape character unlessNO_BACKSLASH_ESCAPESis set. - No transactional DDL. Every DDL statement commits implicitly, so a
migration that fails half way leaves its earlier statements applied and
no history row is written.
Migratordoes not wrap MySQL migrations in a transaction for that reason. Keep MySQL migrations small (one schema change each) so a failure is easy to repair. AUTO_INCREMENTprimary keys:BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY.MODIFY COLUMNreplaces the whole column definition, so anAlterFieldalways restates type, nullability and default.- Foreign keys are table-level
CONSTRAINT .. FOREIGN KEYclauses named<table>_<column>_fk. MySQL parses an inlineREFERENCESon a column but ignores it, so it is never used. InnoDB also rejectsON DELETE SET DEFAULT, which is reported as an error. - Keyed
TEXT.TEXT,BLOBandJSONcolumns cannot be a primary key,UNIQUEor indexed without a prefix length, and this editor never guesses one. Give such fields amax_length(aVARCHAR) instead. Literal defaults on these types are written asDEFAULT ('..'). DROP INDEXneeds its table (DROP INDEX name ON table); a unique constraint is dropped as an index and a check constraint withDROP CHECK.DbDefault::NowisCURRENT_TIMESTAMP(6), matchingDATETIME(6).
Column types follow the MySQL backend’s storage table: TINYINT(1),
DATETIME(6) (UTC), TIME(6), CHAR(36) for UUIDs, JSON, DOUBLE.
A decimal without precision becomes DECIMAL(38,10) (a bare DECIMAL is
DECIMAL(10,0) and would round to an integer).
Functions§
- quote_
ident - Quote
identwith backticks; embed a backtick by doubling it. - quote_
string - Quote a MySQL string literal (quotes doubled, backslashes escaped).