Django Models "IndexError: Index Index Out of Range" Pydev

I have a Django project in Eclipse PyDev.

I have a views.py file that has a line:

from models import ingredient2

In models.py, I have:

from django.db import models
class ingredient2(models.Model):
     ingredient     = models.CharField(max_length=200)

When I try to run the application, I get the following error:

File "C:\Python27\lib\site-packages\django\db\models\base.py", line 54, in __new__
kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range

I synchronized the database and started the server.

I went to base.py and added 2 print statements (yes, I probably shouldn't edit the Django files):

if getattr(meta, 'app_label', None) is None:
            # Figure out the app_label by looking one level up.
            # For 'django.contrib.sites.models', this would be 'sites'.
            model_module = sys.modules[new_class.__module__]
            print model_module #ADDED
            print model_module.__name__ #ADDED
            kwargs = {"app_label": model_module.__name__.split('.')[-2]}

They print:

<module 'models' from 'C:\Users\Tine\workspace\slangen\slangen2\bolig\models.pyc'>

models

manage.py is located in the Bolig folder. I think the correct application shortcut will be "bolig". The application worked a few months ago, and now, when I return to it, something is wrong. I am creating other projects in PyDev.

+5
source share
6 answers

, , ... django, . .

0

meta app_label :

class Foo:
    id = models.BigIntegerField(primary_key=True)
    class Meta:
        app_label = 'foo'
+8

-

from models import ingredient2

:

from your_app_name.models import ingredient2
+3

kwargs = {"app_label": model_module.__name__.split('.')[-2]} PyDev. , . , .

0

, Eclipse, Django PyDev. ( .py , ), PyDev ( ), "", .

0

, models.py

when I import models into another .py, say view.py, it does not cause an error when running views.py

but when I run models.py it causes the same error.

so I just won’t run in models.py

-1
source

All Articles