Django app上的外键约束错误

时间:2014-03-27 05:54:38

标签: python django django-models

我正在尝试将第三个类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数据库

1 个答案:

答案 0 :(得分:1)

也许您的问题是您运行了syncdb,假设它会改变表以匹配您的模型更改。不幸的是,它没有那样做。有一些单独的工具,例如South,可以帮助进行数据库迁移。