Skip to content

[BUG] 无法存储 Emoji 表情及升级 utf8mb4 时遭遇外键约束错误 (Error 3780) #464

@Wuxiuga

Description

@Wuxiuga

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

在使用默认数据库 schema 初始化后,尝试向 chat_message 表插入包含 Emoji 表情(如 🔍, ✅)的消息时,报错 Incorrect string value。

Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x94\x8D *...' for column 'content'
...
ERROR 3780 (HY000): Referencing column 'session_id' and referenced column 'id' in foreign key constraint 'chat_message_ibfk_1' are incompatible.

Expected Behavior

验证过的解决方案:修改字符集为utf8mb4,因为有外键约束,修改比较麻烦一些,笔者为mysql8.0版本

-- 1. 临时关闭外键检查,允许结构变更
SET FOREIGN_KEY_CHECKS = 0;

-- 2. 删除子表上的外键约束
ALTER TABLE `chat_message` DROP FOREIGN KEY `chat_message_ibfk_1`;

-- 3. 升级子表 (chat_message) 到 utf8mb4
ALTER TABLE `chat_message` 
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 4. 升级父表 (chat_session) 到 utf8mb4
ALTER TABLE `chat_session` 
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 5. 重新创建外键约束
ALTER TABLE `chat_message` 
ADD CONSTRAINT `chat_message_ibfk_1` 
FOREIGN KEY (`session_id`) REFERENCES `chat_session` (`id`) 
ON DELETE CASCADE;

-- 6. 恢复外键检查
SET FOREIGN_KEY_CHECKS = 1;

Steps To Reproduce

No response

Environment

Spring AI Alibaba DataAgent version(s):

Debug logs

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions