I have a Django app with the following in its models.py file:
我有一个Django应用程序,它的模型如下。py文件:
from django.db import models
class Event(models.Model):
date = models.DateField()
name = models.TextField(max_length=60)
venue = models.ForeignKey(Venue)
def __unicode__(self):
return self.name
class Venue(models.Model):
name = models.TextField(max_length=60)
street_address = models.TextField(max_length=60)
locality = models.TextField(max_length=60)
region = models.TextField(max_length=60)
postal_code = models.TextField(max_length=60)
country_name = models.TextField(max_length=60)
latitude = models.DecimalField(max_digits=9, decimal_places=6)
longitude = models.DecimalField(max_digits=9, decimal_places=6)
def __unicode__(self):
return self.name
But when I run python manage.py syncdb
I get the following error:
但是当我运行python管理时。py syncdb我得到以下错误:
NameError: name 'Venue' is not defined
NameError:没有定义“地点”的名称
Why is this when class Venue
is in the file? Have I done something wrong? I’ve just been following the Django tutorial at https://docs.djangoproject.com/en/1.5/intro/tutorial01/.
为什么当类地在文件中?我做错什么了吗?我刚刚学习了Django教程,网址是https://docs.djangoproject.com/en/1.5/intro/tutorial01/。
1 个解决方案
#1
18
Move the definition of Venue
before the definition of Event
. The reason is that Event references the Venue class in its ForeignKey relationship before Venue is defined.
在事件定义之前移动场地的定义。其原因是在定义场地之前,事件在其对外关系中引用了场馆类。
Or you can do this:
或者你可以这样做:
venue = models.ForeignKey('Venue')
#1
18
Move the definition of Venue
before the definition of Event
. The reason is that Event references the Venue class in its ForeignKey relationship before Venue is defined.
在事件定义之前移动场地的定义。其原因是在定义场地之前,事件在其对外关系中引用了场馆类。
Or you can do this:
或者你可以这样做:
venue = models.ForeignKey('Venue')