Django 1.9 迁移问题

Django 1.9 Migration Problems

我正在尝试将我的 1.8 应用程序转换到 Django 1.9。只需为旧数据库创建迁移就可以了,但是当我尝试使用 migrate 创建新数据库时,我得到:

"Error creating new content types. Please make sure contenttypes " RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

我已经对此进行了相当多的测试,如果我这样做,我可以让它重新构建:从 URL 中删除我的网站,迁移,将其添加回来,然后再次迁移......但那是超级笨拙的,而不是我正在寻找干净的建筑。似乎 Django/core/management/base.py line 398 -> self.check() 在迁移发生之前被调用,缺少数据库会引发错误并在设置数据库之前退出(catch 22)。我已经通过注释对此进行了测试,这也将允许它构建数据库。

有人对解决此问题的好方法或我的应用程序中可能存在的潜在问题有什么建议吗?

编辑 完整的堆栈跟踪:

(test) C:\website\test\rpi_csdt_community>python manage.py migrate
C:\website\test\rpi_csdt_community\collected_static/
C:\website\test\rpi_csdt_community\rpi_csdt_community\urls.py:27: RemovedInDjang
o110Warning: Support for string view arguments to url() is deprecated and will b
e removed in Django 1.10 (got rpi_csdt_community.views.home). Pass the callable
instead.
  url(r'^$', 'rpi_csdt_community.views.home', {}, 'home'),

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\website\test\lib\site-packages\django\core\management\__init__.py", l
ine 353, in execute_from_command_line
    utility.execute()
  File "C:\website\test\lib\site-packages\django\core\management\__init__.py", l
ine 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\website\test\lib\site-packages\django\core\management\base.py", line
348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\website\test\lib\site-packages\django\core\management\base.py", line
398, in execute
    self.check()
  File "C:\website\test\lib\site-packages\django\core\management\base.py", line
426, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\website\test\lib\site-packages\django\core\checks\registry.py", line
75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\website\test\lib\site-packages\django\core\checks\urls.py", line 13,
in check_url_config
    return check_resolver(resolver)
  File "C:\website\test\lib\site-packages\django\core\checks\urls.py", line 23,
in check_resolver
    for pattern in resolver.url_patterns:
  File "C:\website\test\lib\site-packages\django\utils\functional.py", line 33,
in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\website\test\lib\site-packages\django\core\urlresolvers.py", line 417
, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\website\test\lib\site-packages\django\utils\functional.py", line 33,
in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\website\test\lib\site-packages\django\core\urlresolvers.py", line 410
, in urlconf_module
    return import_module(self.urlconf_name)
  File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\website\test\rpi_csdt_community\rpi_csdt_community\urls.py", line 29,
 in <module>
    url(r'', include('project_share.urls')),
  File "C:\website\test\lib\site-packages\django\conf\urls\__init__.py", line 52
, in include
    urlconf_module = import_module(urlconf_module)
  File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\website\test\rpi_csdt_community\project_share\urls.py", line 4, in <m
odule>
    from project_share.views import ProjectList, ProjectTagList, ApplicationList
, DemoList
  File "C:\website\test\rpi_csdt_community\project_share\views.py", line 54, in
<module>
    class ProjectList(SearchableListMixin, SortableListMixin, ListView):
  File "C:\website\test\rpi_csdt_community\project_share\views.py", line 59, in
ProjectList
    queryset = Project.approved_projects().all()
  File "C:\website\test\rpi_csdt_community\project_share\models.py", line 150, i
n approved_projects
    return Project.objects.filter(approved=True)
  File "C:\website\test\lib\site-packages\django\db\models\manager.py", line 122
, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\website\test\lib\site-packages\secretballot\__init__.py", line 58, in
 get_queryset
    content_type = ContentType.objects.get_for_model(self.model).id
  File "C:\website\test\lib\site-packages\django\contrib\contenttypes\models.py"
, line 80, in get_for_model
    "Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure contenttypes is
 migrated before trying to migrate apps individually.

通过替换修复:

queryset = Project.approved_projects().all()

在我看来:

def get_queryset(self):
    return Project.approved_projects().all()

我猜它甚至在构建数据库之前就尝试测试视图……愚蠢的错误。但我把它留在这里以防其他人遇到困难。