Skip to main content
 首页 » 编程设计

python之南django.db.utils.IntegrityError : django_content_type. name may not be NULL while running unit tests

2025年05月04日28wayfarer

我收到此错误 django.db.utils.IntegrityError: django_content_type.name may not be NULL通过 nosetest 运行测试时.

我已经按照 south 教程中的说明完成了所有操作 - 初始迁移、假迁移等。 通过runserver正常运行站点命令就像魅力一样,但在使用 test 时命令 - 以上错误。

此外,在我的开发环境中,我正在使用 sqlite数据库,我使用 django-nose 作为测试运行器(在 INSTALLED_APPS 的最后。

有什么线索吗?

请您参考如下方法:

好的 - 我已经设法自己解决了这个问题。

在我看来,集成由 django 测试命令创建的 south、nose 和内存数据库存在问题。

我所要做的就是在我的开发设置中定义 TEST_NAME - 就像这样:

DATABASES = { 
    'default': { 
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': 'database.sqlite', 
        'TEST_NAME': 'test_database.sqlite', 
    } 
} 

就是这样:)