MySQL error 1005 signals that InnoDB failed to create a table, often due to foreign-key, naming, or storage issues.
MySQL Error 1005: ER_CANT_CREATE_TABLE occurs when InnoDB cannot create a table because of malformed foreign keys, duplicate names, missing indexes, or file-system limits. Check foreign-key references, ensure unique table and index names, and verify InnoDB file-path permissions to resolve the problem.
Can't create table '%s' (errno: %d)
The exact message is "Can't create table '.
' (errno: )". MySQL raises it when the InnoDB storage engine cannot finish CREATE TABLE. The errno value reveals the underlying operating-system or InnoDB issue.
Error 1005 uses SQLSTATE HY000, marking it as a general internal error.
The most frequent sub-error is errno 150, indicating a foreign key problem, but other codes such as 1, -1, 121, and 1007 appear in different contexts.
The error is triggered at table-creation time during a CREATE TABLE or ALTER TABLE ... ENGINE=InnoDB statement.
It can also surface when tools like mysqldump or ORMs replay DDL statements during migrations or restores.
Developers notice the failure immediately because the intended table is missing, causing subsequent INSERT or SELECT statements against that table to fail.
Unresolved, the error blocks schema migrations, halts CI/CD pipelines, and prevents new application features from shipping. In production, failed restores leave databases in inconsistent states, risking data loss and downtime.
.
The referenced or referencing columns differ in data type, length, collation, or signedness, making the constraint invalid.
The CREATE statement introduces a name that already exists in the schema or clashes with an internal InnoDB table.
The foreign key points to a table that does not exist yet or is being created in the same batch without proper ordering.
ROW_FORMAT, KEY_BLOCK_SIZE, or partitioning options conflict with global InnoDB settings.
InnoDB cannot write the .ibd file because of disk-space exhaustion or OS permission denial.
.
Immediately run SHOW WARNINGS and SHOW ENGINE INNODB STATUS; the last InnoDB entry lists errno and explanation.
SET FOREIGN_KEY_CHECKS=0 prevents validation during creation, but constraints still need to be valid for later re-enabling. Fix the root mismatch instead.
Yes. MySQL 8 enforces stricter type matching and character set compatibility in foreign keys than 5.6 or 5.7, making the error more common after upgrades.
Galaxy's AI copilot validates foreign keys, suggests compliant data types, and highlights name collisions before you run CREATE TABLE, reducing error 1005 occurrences.