标签:info tps cti arc 关联表 const set img ref
1.迁移先需要失败一次(既然出现了这个错误,说明已经迁移了一次)
2.修改当前表外键字段的字符集(或者说COLLATE),修改为外键关联表的字符集
SHOW CREATE TABLE `user_group` (查看创建表的命令)
ALTER TABLE user_group_info MODIFY employee_id VARCHAR(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3.手动给新表添加外键约束
alter table user_group_info add constraint `user_group_info_id_869a94b79388475b_fk_employee_info_id` foreign key (`employee_id`) REFERENCES `employee_info` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
4.第二次迁移加上fake
python manage.py migrate --fake
Django 迁移错误 Cannot add foreign key constraint
标签:info tps cti arc 关联表 const set img ref
原文地址:https://www.cnblogs.com/fixdq/p/11703649.html