MySQL 3780 에러는 컬럼 혹은 테이블간의 타입이 맞지 않아서 발생한 문제다.
따라서 크게 두가지를 확인해보도록 한다.
# 테이블 컬럼 타입 조회
$ desc <테이블명>;
ex) desc notifications;
+------------+--------------+------+-----+-------------------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------------+-------------------+
| id | int | NO | PRI | NULL | auto_increment |
| title | varchar(30) | NO | | NULL | |
| type | int | NO | | NULL | |
| contents | varchar(100) | NO | | NULL | |
| isRead | tinyint | NO | | 0 | |
| target_url | varchar(255) | YES | | NULL | |
| date | datetime | NO | | NULL | |
| created_at | datetime | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
| updated_at | datetime | YES | | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
+------------+--------------+------+-----+-------------------+-------------------+
character set
이 동일하지 않기 때문이다. 따라서 다음 명령어를 입력해서 동일한 테이블 character set 인지 확인해 줄 수 있도록 한다. (별도로 character set
을 지정하지 않았을 경우 latin1
계열로 설정되어있을 것이다.)$ show full columns from <테이블명>;
ex) show full columns from notifications;
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| id | int | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | |
| title | varchar(30) | utf8mb4_unicode_ci | NO | | NULL | | select,insert,update,references | |
| type | int | NULL | NO | | NULL | | select,insert,update,references | |
| contents | varchar(100) | utf8mb4_unicode_ci | NO | | NULL | | select,insert,update,references | |
| isRead | tinyint | NULL | NO | | 0 | | select,insert,update,references | |
| target_url | varchar(255) | utf8mb4_unicode_ci | YES | | NULL | | select,insert,update,references | |
| date | datetime | NULL | NO | | NULL | | select,insert,update,references | |
| created_at | datetime | NULL | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED | select,insert,update,references | |
| updated_at | datetime | NULL | YES | | CURRENT_TIMESTAMP | DEFAULT_GENERATED | select,insert,update,references | |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
Collation
에 utfmb4_unicode_ci
로 보이는 부분이 테이블의 character set
설정이다. varchar
, char
의 타입을 가진 컬럼에만 나온다. 따라서 varchar
, char
로 외래키를 엮으려고 하는데 에러가 난다면 Collation
값이 동일한지 확인해본다.
끝.