Django - 没有这样的专栏

时间:2014-11-26 14:04:03

标签: django models

我是Django的初学者,我遇到了这个我无法解决的错误。 我只是想添加一个基本模型Bar,它有一个城市和一个国家。 这是models.py:

from django.db import models
# from smart_selects.db_fields import ChainedForeignKey, GroupedForeignKey

DEFAULT_COUNTRY_ID = 1 # id of Israel
DEFAULT_CITY_ID = 1 # id of Herzeliyya
DEFAULT_BARNAME_ID = 1 # id of Bourbon Street

class Country(models.Model):
    # continent = models.CharField(max_length=10, default="Europe")
    country = models.CharField(max_length=20)
    def __unicode__(self):
        return self.country

class City(models.Model):
    city = models.CharField(max_length=20)
    country_of_city = models.ForeignKey(Country, default=DEFAULT_COUNTRY_ID)
    def __unicode__(self):
        return self.city

class BarName(models.Model):
    name = models.CharField(max_length=20)
    city = models.ForeignKey(City, default=DEFAULT_CITY_ID)
    def __unicode__(self):
        return self.name        

class Bar(models.Model):    # The whole detailed BAR.
    country_of_bar = models.ForeignKey(Country, default=DEFAULT_COUNTRY_ID)
    city_of_bar = models.ForeignKey(City, default=DEFAULT_CITY_ID)
    name_of_bar = models.ForeignKey(BarName, default=DEFAULT_BARNAME_ID)

这是我在尝试添加栏时遇到的错误:

OperationalError at /admin/foos/bar/
no such column: foos_bar.country_of_bar_id
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/foos/bar/
Django Version: 1.7.1
Exception Type: OperationalError
Exception Value:    
no such column: foos_bar.country_of_bar_id
Exception Location: /Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 485
Python Executable:  /usr/bin/python
Python Version: 2.7.6

0 个答案:

没有答案