Error Analysis
After the replacement of the database
Character Set error
It is not the same as the character set of the original library and the new library of the foreign key
Figure:
solution:
1. The need to migrate to a single failure (since the emergence of this mistake, explained that it had migrated once)
2. Modify the current character set table foreign key column (or COLLATE), modify the character set associated with the foreign key table
- View the table creation statements (mainly to see the character set foreign key table's primary key)
SHOW the CREATE TABLE `user_group` (see table creation command)
- Modify the character set
ALTER TABLE user_group_info MODIFY employee_id VARCHAR(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3. Manually add a new table to the foreign key constraint
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. The second migration plus fake
python manage.py migrate --fake