【发布时间】:2014-03-27 05:54:38
【问题描述】:
我正在尝试将第三类 noticeTime 限制为外键 email。我使用与第二类 location 相同的语法,但是当我在 noticeTime 上使用它时会引发错误:
Exception Value: no such column: setupNotifications_noticetime.email_id
代码如下:
from django.db import models
# Create your models here.
from django.db import models
class email(models.Model):
email = models.CharField(max_length=200)
def __unicode__(self):
return self.email`
class location(models.Model):
email = models.ForeignKey(email)
zip_code = models.CharField(max_length=5)
def __unicode__(self):
return self.zip_code
class noticeTime(models.Model):
email = models.ForeignKey(email)
time = models.CharField(max_length=200)
def __unicode__(self):
return self.time
这里是 admin.py:
from django.contrib import admin
# Register your models here.
from setupNotifications.models import email
from setupNotifications.models import location
from setupNotifications.models import noticeTime
admin.site.register(email)
admin.site.register(location)
admin.site.register(noticeTime)
我正在使用 sqlite 数据库
【问题讨论】:
-
您发布的代码不会给您提到的错误。贴出完整代码。
-
它是一个 django 应用程序,所以有很多其他文件被引用,不知道我将如何发布所有这些
-
我猜你会在你的views.py中找到它访问noticeTime-Model?你能发布那个文件吗?
-
您在哪里访问
setupNotifications...或更好...您从哪里得到错误/您在做什么? -
请更新/编辑您的问题并添加您的
admin.py的内容
标签: python django django-models