在Django中迁移到mysql [英] migrating to mysql in django
问题描述
我想从sqlite3迁移到Django中的MySQL.首先,我使用以下命令:
I want to migrate from sqlite3 to MySQL in Django. First I used below command:
python manage.py dumpdata > datadump.json
然后,我更改了Django应用程序的设置,并使用新的MySQL数据库对其进行了配置.最后,我使用了以下命令:
then I changed the settings of my Django application and configured it with my new MySQL database. Finally, I used the following command:
python manage.py loaddata datadump.json
但我收到此错误:
integrityError:安装固定装置时出现问题:表中的行 主键为'20'的'django_admin_log'具有无效的foregin键: django_admin_log.user_id包含的值'19'没有 auth_user.id中的相应值.
integrityError: Problem installing fixtures: The row in table 'django_admin_log' with primary key '20' has an invalid foregin key: django_admin_log.user_id contains a value '19' that does not have a corresponding value in auth_user.id.
推荐答案
您的数据存在一致性错误,django_admin_log表引用了不存在的auth_user. sqlite不强制执行外键约束,但mysql强制.您需要修复数据,然后可以将其导入mysql.
You have consistency error in your data, django_admin_log table refers to auth_user which does not exist. sqlite does not enforce foreign key constraints, but mysql does. You need to fix data and then you can import it into mysql.
这篇关于在Django中迁移到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!