我正在使用django-1.5进行新项目,我正在尝试编写模型。 当我尝试包含除CharField(或foriegn键)以外的任何其他字段时出现错误
# 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
但是当我打开与Book相关的链接时,在管理页面上收到错误“no such column:myapp_book.avail_count”。
确切地说: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”会出现相同的错误。
我搜索了很多地方,但没有任何帮助。请有人告诉我问题是什么。
感谢您的帮助。
答案 0 :(得分:0)
您可以在shell中打开数据库。 然后: