Exception when trying to install Django-Treebeard based on instructions

五迷三道 提交于 2019-12-08 19:28:32

I had the same error today. To fix you first go to your models.py file and in each of the classes you have to add another class:

class Meta:
    app_label = 'app_name' # medCE.delib in your case

I think that you are getting this error because of the period in your app name. If an app name is not provided with the Meta class, Django will try to figure it out by itself by decomposing the folder structure. When that happens, it decomposes at the 'period location' and figures out the app name to be medCE or delib in your case, which is obviously not your app name.

I know the question is old, but hopefully it'll help future viewers

You can browse the Django source-code online:

https://github.com/django/django/blob/master/django/db/models/base.py#L90

The relevant code that throws the exception has this comment:

# Figure out the app_label by looking one level up.
# For 'django.contrib.sites.models', this would be 'sites'.

So it seems that the code is trying to determine the app that a model belongs to.

To debug this you could simply modify the base.py to catch the IndexError and raise the model_module.__name__.

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