0

I am using django-1.5 for a new project and am trying to write its models. I get an error when I try to include any other field other than CharField(or the foriegn keys)

# 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='')

I run

python manage.py sql myapp

python manage.py syncdb

python manage.py runserver

but get the error "no such column: myapp_book.avail_count" on the admin page when I open the link related to Book.

to be precise:

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

When I comment out the line containing the "IntegerField" or change it to Charfield I get the same error for "BooleanField".

I have searched many a places but nothing helps.Please can anybody tell me what the problem can be.

Thank you for any help.

Fernando Freitas Alves
  • 3,709
  • 3
  • 26
  • 45
akki
  • 2,021
  • 1
  • 24
  • 35

1 Answers1

0

You can open you database in shell. Then:

  1. drop database nameinsettings;
  2. create database nameinsettings;
  3. manage.py syncdb
cehmja
  • 130
  • 6
  • I am using the default sqlite3 that gets installed with django itself and tried to search how to execute from shell..can you tell me how I can do that ? – akki Dec 21 '13 at 23:21
  • if you have sqlite3 then http://stackoverflow.com/questions/5326918/how-to-drop-database-in-sqlite (only delete file) – cehmja Dec 22 '13 at 07:48