ImportError: cannot import name update_all_contenttypes

雨燕双飞 提交于 2019-11-27 07:44:16

问题


I upgraded recently to Django 1.8. In previous versions of Django, the following import was fine:

from django.contrib.contenttypes.management import update_all_contenttypes

But update_all_contenttypes appears to have been silently removed in Django 1.8 (it was there in 1.7.7). I'm not seeing anything in the 1.8 release notes about its removal... Does anyone know what the modern replacement is for that function?


回答1:


It's unclear why that function was removed in 1.8, but it appears that the modern replacement is to just re-invent that wheel:

from django.apps import apps
from django.contrib.contenttypes.management import update_contenttypes

def update_all_contenttypes(**kwargs):
    for app_config in apps.get_app_configs():
        update_contenttypes(app_config, **kwargs)



回答2:


It seems django team has removed the update_contenttypes function without a mention in the release notes because isn't a documented, public API. (as the said here: https://code.djangoproject.com/ticket/28092)

Now you can use instead the new function create_contenttypes, as you can see here: https://github.com/django/django/commit/6a2af01452966d10155b720f4f5e7b09c7e3e419



来源:https://stackoverflow.com/questions/29550102/importerror-cannot-import-name-update-all-contenttypes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!