生产问题:django中sqlite3到postgresql的迁移问题



我正试图将我的django项目从sqlite3迁移到postgresql。我在开发中成功地做到了这一点,但在生产中却出现了错误。

我用这个命令创建转储:

manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json

然后我更改了设置中的数据库.py

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}

然后我排除如下内容类型:

python3 manage.py shell
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()

但我得到了这个错误:

django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table 
"django_admin_log" violates foreign key constraint 
"django_admin_log_content_type_id_c4bce8eb_fk_django_co"
DETAIL:  Key (content_type_id)=(7) is not present in table "django_content_type".

请帮助

好吧,我成功地找到并迁移了。感谢安基特、范昂森和莫斯塔法·加迪米

我在这里一步一步地遵循Mostafa Ghadimi的回答。

还清除了ankit 建议的缓存

最新更新