MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 1824 (HY000): Failed to open the referenced table

The table named after REFERENCES does not exist where MySQL is looking for it.

MySQL 8.4.13
1824 (HY000): Failed to open the referenced table 'customer'

Jump to a cause

  1. 01Typo in the parent table name
  2. 02The parent table is in another database
  3. 03Creating the child table before the parent (dump or script order)

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

When you create a foreign key, MySQL opens the parent table named after REFERENCES. If that table is not found, it stops with ERROR 1824 and shows the name it tried.

The table name is looked up in the current database unless you write db.table. The message stays in English even with Korean or Japanese lc_messages. Below are three causes verified on MySQL 8.4.

01Typo in the parent table name

The parent table is customers, but the foreign key says REFERENCES customer (id). The error shows the wrong name: 'customer'.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
OUTPUT
Query OK, 0 rows affected (0.02 sec)
Reproducerun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  FOREIGN KEY (customer_id) REFERENCES customer (id));
✕ ERROR
ERROR 1824 (HY000): Failed to open the referenced table 'customer'
Checkrun as lab_a
SHOW TABLES LIKE 'customer%';
OUTPUT
+-----------------------------+
| Tables_in_lab_a (customer%) |
+-----------------------------+
| customers                   |
+-----------------------------+
1 row in set (0.00 sec)

SHOW TABLES LIKE 'customer%' shows the real name customers. With the correct name the CREATE TABLE succeeds.

After the fixrun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  FOREIGN KEY (customer_id) REFERENCES customers (id));
✓ SUCCESS
Query OK, 0 rows affected (0.02 sec)

02The parent table is in another database

customers exists only in master_db. Writing REFERENCES customers (id) while connected to lab_a looks for lab_a.customers, so it is not found.

Setup
Setuprun as root
CREATE DATABASE master_db;
CREATE TABLE master_db.customers (id INT PRIMARY KEY, name VARCHAR(50));
GRANT REFERENCES ON master_db.* TO lab_a;
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  FOREIGN KEY (customer_id) REFERENCES customers (id));
✕ ERROR
ERROR 1824 (HY000): Failed to open the referenced table 'customers'
Checkrun as lab_a
SELECT table_schema, table_name FROM information_schema.tables WHERE table_name = 'customers';
OUTPUT
+--------------+------------+
| TABLE_SCHEMA | TABLE_NAME |
+--------------+------------+
| master_db    | customers  |
+--------------+------------+
1 row in set (0.00 sec)

information_schema.tables shows customers in master_db. Qualify the name: REFERENCES master_db.customers (id). The user also needs the REFERENCES privilege on that table; here it was granted in setup.

After the fixrun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  FOREIGN KEY (customer_id) REFERENCES master_db.customers (id));
✓ SUCCESS
Query OK, 0 rows affected (0.02 sec)

03Creating the child table before the parent (dump or script order)

In a script that creates orders before customers, the foreign key points to a table that does not exist yet. SHOW TABLES returns an empty set.

Reproducerun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers (id));
✕ ERROR
ERROR 1824 (HY000): Failed to open the referenced table 'customers'
Checkrun as lab_a
SHOW TABLES;
OUTPUT
Empty set (0.00 sec)

Best is to create the parent first. When you cannot change the order (for example a dump), run the script between SET FOREIGN_KEY_CHECKS = 0 and SET FOREIGN_KEY_CHECKS = 1. The child is created first, then the parent, and information_schema.referential_constraints shows fk_orders_customer pointing to customers.

After the fixrun as lab_a
SET FOREIGN_KEY_CHECKS = 0;
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT,
  CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers (id));
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
SET FOREIGN_KEY_CHECKS = 1;
SELECT constraint_name, referenced_table_name FROM information_schema.referential_constraints WHERE constraint_schema = 'lab_a';
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.00 sec)

+--------------------+-----------------------+
| CONSTRAINT_NAME    | REFERENCED_TABLE_NAME |
+--------------------+-----------------------+
| fk_orders_customer | customers             |
+--------------------+-----------------------+
1 row in set (0.00 sec)

FAQ

What does Failed to open the referenced table mean in MySQL?

MySQL cannot find the table after REFERENCES. Check the spelling, the database, and whether the parent has been created yet.

How do I reference a table in another database in a foreign key?

Write it with the database name: REFERENCES other_db.parent (id). You need the REFERENCES privilege on it.

How do I create tables with foreign keys in any order?

Run SET FOREIGN_KEY_CHECKS = 0; before the CREATE statements and set it back to 1 after.

Is ERROR 1824 shown in other languages?

In our test on MySQL 8.4 the message was English even with lc_messages set to Korean or Japanese.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13