1281
MariaDBerrorddlhigh confidence

Foreign key not supported with partitioning

Production Risk

Low — DDL fails; no data affected.

What this means

An attempt was made to combine InnoDB foreign keys with table partitioning, which was not supported in MySQL 5.6 and earlier.

Why it happens
  1. 1CREATE TABLE with both FOREIGN KEY and PARTITION BY clauses on MySQL <= 5.6
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE child (id INT, pid INT, FOREIGN KEY (pid) REFERENCES parent(id)) PARTITION BY HASH(id) PARTITIONS 4;

expected output

ERROR 1281 (HY000): Foreign key not supported in combination with partitioning

Fix 1

Upgrade to MySQL 8.0

Why this works

MySQL 8.0 supports foreign keys on partitioned InnoDB tables.

Fix 2

Remove partitioning

Why this works

Use a non-partitioned table if foreign keys are required on older versions.

What not to do

Version notes

Sources
Official documentation ↗

MySQL 8.0 — 1281 ER_FOREIGN_KEY_ON_PARTITIONED

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors