繁体   English   中英

Django 应用程序上的外键约束错误

[英]Foreign key constraint error on Django app

我正在尝试将这个第三类noticeTime限制为外键email 我使用的语法与适用于 2nd class 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 数据库

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM