我正在使用django-1.5作为新项目,并且正在尝试编写它的模型。 我得到一个错误,当我尝试包括比CharField其他任何其他领域(或foriegn键)除CharField之外没有其他字段在django工作
# Create your models here.
from django.db import models
class Student_Year(models.Model):
FIRST = '1st'
SECOND = '2nd'
THIRD = '3rd'
FOURTH = '4th'
YEAR_CHOICES = (
(FIRST, 'First'),
(SECOND, 'Second'),
(THIRD, 'Third'),
(FOURTH, 'Fourth'),
)
class Book(models.Model):
name = models.CharField(max_length=100)
author = models.CharField(max_length=40,primary_key=True)
avail_count = models.IntegerField()
def __unicode__(self):
return self.name
class Profile(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField(max_length=254,primary_key=True)
phone_number = models.CharField(max_length=10)
room_number = models.CharField(max_length=10)
year = models.CharField(max_length=3,choices=Student_Year.YEAR_CHOICES)
enrollment_number = models.CharField(max_length=8)
synced_facebook = models.BooleanField
blocked = models.BooleanField
def __unicode__(self):
return self.email
class User(models.Model):
email = models.OneToOneField(Profile)
password = models.CharField(max_length=32)
class Item(models.Model):
ITEM_STATUS = (
('0','no_request'),
('1','request_to_buy'),
('2','sold'),
)
name = models.ForeignKey(Book)
edition = models.CharField(max_length=15)
seller = models.ForeignKey(Profile)
buy_request = models.CharField(max_length=1,choices=ITEM_STATUS,default='0')
buyer = models.ForeignKey(Profile,related_name='+',default='')
other_details = models.TextField(default='')
我跑
python manage.py sql myapp
python manage.py syncdb
python manage.py runserver
,但得到的错误“没有这样的列:myapp_book.avail_count “当我打开与Book相关的链接时,在管理页面上。
准确地说:
DatabaseError at /admin/myapp/book/
no such column: myapp_book.avail_count
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/myapp/book/
Django Version: 1.5
Exception Type: DatabaseError
Exception Value:
no such column: myapp_book.avail_count
Exception Location: C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 362
Python Executable: C:\Python27\python.exe
Python Version: 2.7.5
Python Path:
['E:\\Kryptonite\\django\\git\\myapp\\website',
'C:\\Python27\\lib\\site-packages\\south-0.8.4-py2.7.egg',
'C:\\Windows\\SYSTEM32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time: Sun, 22 Dec 2013 03:50:39 +0530
当我注释掉包含“IntegerField”线或将其更改为Charfield我得到同样的错误“BooleanField”。
找遍许多地方,但没有helps.Please有谁能够告诉我,问题就可以有什么。
谢谢你的帮助。
你知道'syncdb'不会改变任何东西,对吗? –
是啊..我每次都使用flush来确保每一次更改都被考虑到 – akki
你知道'flush'不会删除表格,对吧? –