开发者

python manage.py syncdb doesn't pull from models.py

I'm not getting a python manage.py syncdb to create tables for my models; this is apparently because an exception is thrown on attempted import of my models and I am somewhat puzzled by the exception:

jhayward@jhayward81QDLD1 ~/project
$ python manage.py shell
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import models
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/jhayward/project/models.py", line 23, in <module>
    class architecture(models.Model):
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 48, in
__new__
    kwargs = {"app_label":开发者_开发百科 model_module.__name__.split('.')[-2]}
IndexError: list index out of range
>>>

Importing models as unadorned django.db.models does not help. The models.py is in the same directory as I'm trying to import from; it doesn't seem to behave any differently when I add the current directory to my PYTHONPATH.

What is going on in this error message, and what do I need to do to help it?

The basic structure of the models.py is:

from django.db import models

example_choice = (
    (0, u'first choice'),
    (1, u'second choice'),
    )

[more such choices]

class architecture(models.Model):                                                 
    name = models.TextField(null = True, blank = True)

[more such classes, with more fields and some interconnections but no more sophisticated syntax]


You must have an application package (e.g. myapp) and models must be within it (myapp/models.py) Then you can import myapp.models or from myapp import models.

The error is because django tries to find the appname as the package that contains the models module (the path to the models module must at least have 2 levels of depth).

Besides, the app must be declared within INSTALLED_APPS


Models should be contained within an app, not within the project directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜