MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 3780 (HY000): Referencing column and referenced column in foreign key constraint are incompatible

The child column and the parent column of the foreign key have different types (size, signedness or character set).

MySQL 8.4.13
3780 (HY000): Referencing column 'customer_id' and referenced column 'id' in foreign key constraint 'fk_orders_customer' are incompatible.

Jump to a cause

  1. 01INT child column referencing a BIGINT primary key
  2. 02Signed INT referencing an INT UNSIGNED primary key
  3. 03String columns with different character sets (old latin1 table, new utf8mb4 table)

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

3780 means the two columns of a foreign key do not have the same type. The message names both columns and the constraint, so the first step is to compare their column_type (and character set for strings) in information_schema.columns.

The column types must match exactly: int and bigint differ, and so do int and int unsigned. The error is in English in every language.

01INT child column referencing a BIGINT primary key

customers.id is BIGINT AUTO_INCREMENT, but orders.customer_id was created as INT. Adding the FK with ALTER TABLE fails. The check shows bigint and int side by side.

Setup
Setuprun as lab_a
CREATE TABLE customers (id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
ALTER TABLE orders ADD CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers (id);
✕ ERROR
ERROR 3780 (HY000): Referencing column 'customer_id' and referenced column 'id' in foreign key constraint 'fk_orders_customer' are incompatible.
Checkrun as lab_a
SELECT table_name, column_name, column_type FROM information_schema.columns WHERE table_schema = 'lab_a' AND ((table_name = 'customers' AND column_name = 'id') OR (table_name = 'orders' AND column_name = 'customer_id'));
OUTPUT
+------------+-------------+-------------+
| TABLE_NAME | COLUMN_NAME | COLUMN_TYPE |
+------------+-------------+-------------+
| customers  | id          | bigint      |
| orders     | customer_id | int         |
+------------+-------------+-------------+
2 rows in set (0.00 sec)
Fixrun as lab_a
ALTER TABLE orders MODIFY customer_id BIGINT;
OUTPUT
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

Change the child column to the parent's type: ALTER TABLE orders MODIFY customer_id BIGINT;. Then the same ALTER TABLE ... ADD CONSTRAINT succeeds.

After the fixrun as lab_a
ALTER TABLE orders ADD CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers (id);
✓ SUCCESS
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

02Signed INT referencing an INT UNSIGNED primary key

categories.id is int unsigned, and the new products.category_id is plain INT. Both are 4-byte integers, but signed and unsigned are different types for a foreign key.

Setup
Setuprun as lab_a
CREATE TABLE categories (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50));
OUTPUT
Query OK, 0 rows affected (0.02 sec)
Reproducerun as lab_a
CREATE TABLE products (id INT PRIMARY KEY, category_id INT, FOREIGN KEY (category_id) REFERENCES categories (id));
✕ ERROR
ERROR 3780 (HY000): Referencing column 'category_id' and referenced column 'id' in foreign key constraint 'products_ibfk_1' are incompatible.
Checkrun as lab_a
SELECT column_name, column_type FROM information_schema.columns WHERE table_schema = 'lab_a' AND table_name = 'categories' AND column_name = 'id';
OUTPUT
+-------------+--------------+
| COLUMN_NAME | COLUMN_TYPE  |
+-------------+--------------+
| id          | int unsigned |
+-------------+--------------+
1 row in set (0.00 sec)

Create the child column as INT UNSIGNED too. The CREATE TABLE then succeeds.

After the fixrun as lab_a
CREATE TABLE products (id INT PRIMARY KEY, category_id INT UNSIGNED, FOREIGN KEY (category_id) REFERENCES categories (id));
✓ SUCCESS
Query OK, 0 rows affected (0.02 sec)

03String columns with different character sets (old latin1 table, new utf8mb4 table)

depts was created with DEFAULT CHARSET = latin1, as in an old database. The new emps table gets the database default, utf8mb4 / utf8mb4_0900_ai_ci. Both columns are VARCHAR(10), but the character sets differ, so the FK is rejected.

Setup
Setuprun as lab_a
CREATE TABLE depts (code VARCHAR(10) PRIMARY KEY, name VARCHAR(50)) DEFAULT CHARSET = latin1;
OUTPUT
Query OK, 0 rows affected (0.02 sec)
Reproducerun as lab_a
CREATE TABLE emps (id INT PRIMARY KEY, dept_code VARCHAR(10), FOREIGN KEY (dept_code) REFERENCES depts (code));
✕ ERROR
ERROR 3780 (HY000): Referencing column 'dept_code' and referenced column 'code' in foreign key constraint 'emps_ibfk_1' are incompatible.
Checkrun as lab_a
SELECT table_name, character_set_name, collation_name FROM information_schema.columns WHERE table_schema = 'lab_a' AND table_name = 'depts' AND column_name = 'code';
SELECT @@character_set_database, @@collation_database;
OUTPUT
+------------+--------------------+-------------------+
| TABLE_NAME | CHARACTER_SET_NAME | COLLATION_NAME    |
+------------+--------------------+-------------------+
| depts      | latin1             | latin1_swedish_ci |
+------------+--------------------+-------------------+
1 row in set (0.00 sec)

+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4                  | utf8mb4_0900_ai_ci   |
+--------------------------+----------------------+
1 row in set (0.00 sec)
Fixrun as lab_a
ALTER TABLE depts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
OUTPUT
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

Convert the parent table to the same character set: ALTER TABLE depts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;. Then the same CREATE TABLE succeeds. CONVERT TO rewrites the whole table, so on a large table plan for the time it takes.

After the fixrun as lab_a
CREATE TABLE emps (id INT PRIMARY KEY, dept_code VARCHAR(10), FOREIGN KEY (dept_code) REFERENCES depts (code));
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

FAQ

How do I fix Referencing column and referenced column are incompatible?

Compare the two columns in information_schema.columns (column_type, character_set_name, collation_name) and make the child column exactly match the parent.

Can a foreign key from INT reference BIGINT in MySQL?

No. In the test, INT to BIGINT and INT to INT UNSIGNED both failed with 3780. Use the same type and signedness on both sides.

Why do two VARCHAR(10) columns give error 3780?

Their character sets differ, for example latin1 on an old table and utf8mb4 on a new one. Convert one table so both use the same character set.

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