【问题标题】:django reset contenttypes mismatchdjango 重置内容类型不匹配
【发布时间】:2013-04-20 09:20:48
【问题描述】:

已删除我的数据库。

已运行 SyncDb。

尝试从转储加载..-python manage.py loaddata dump.json.

Get-"

已运行“python manage.py reset contenttypes”

但是得到-

 Error: Error: contenttypes couldn't be reset. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset contenttypes'. That's the SQL this command wasn't able to run.
The full error: (1217, 'Cannot delete or update a parent row: a foreign key constraint fails')

尝试运行:

从 django.core 导入管理

management.call_command("flush", verbosity=, interactive=False)

management.call_command("完全重置", "contenttypes", verbosity=, interactive=False)

management.call_command("loaddata", "full_test_data.json", verbosity=)

但是get-语法错误。

有 python 2.7。和 Django 1.4

有什么想法吗?

【问题讨论】:

    标签: python mysql django


    【解决方案1】:

    尝试设置foreign_key_checksfalse,

    DATABASES = {
        'default': {
            # ...         
            'OPTIONS': {
                "init_command": "SET foreign_key_checks = 0;",
            },
        }
    }
    

    但您绝对应该尝试使用带有 --natural 选项的 dumpdata 命令,以确保您的设备中没有硬编码的内容类型。

    【讨论】:

    • 不幸的是没有工作。是的,下次我做转储数据时,我将使用 -natural。但是现在这样做有点晚了:-(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 2015-05-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多