我正在尝试将我的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.
我已经对此进行了相当多的测试,如果我:我从网址中删除我的网站,迁移,添加回来,然后重新迁移,我可以让它构建新鲜的...但是那个超级janky,以及不是我想要的干净的构造。似乎Django / core / management / base.py第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.
答案 0 :(得分:0)
通过替换修复:
queryset = Project.approved_projects().all()
在我看来:
def get_queryset(self):
return Project.approved_projects().all()
我想它甚至在构建数据库之前就试图测试视图......愚蠢的错误。但是我要把它留在这里以防其他人与之斗争。