0

I'm new for python,I build a table in models.py like this:

class book(models.Model):
    name = models.CharField(max_length = 20)
    grade = models.CharField(max_length = 20, blank = True, null = True)
    def __unicode__(self):
        return self.name +self.grade + self.nick

now ,I want to insert a column to the table book,when I rewrite the code :

class book(models.Model):
    name = models.CharField(max_length = 20)
    grade = models.CharField(max_length = 20, blank = True, null = True)
    nick = models.CharField(max_length = 20)  
    def __unicode__(self):
        return self.name +self.grade + self.nick

but,when I run the command :python manage.py syncdb is OK but,when I run :

from db.models import book book.objects.all() here is wrong,

OperationalError: no such column: db_book.nick

I really don't know how to change it ,by the way ,how to drop the whole table?just like in MySQL? thanks

  • possible duplicate of [Django flush vs sqlclear & syncdb](http://stackoverflow.com/questions/7598024/django-flush-vs-sqlclear-syncdb) – rnevius May 11 '14 at 15:40

2 Answers2

1

You need to tell to your database that your models change everytime you modify them. You should learn how to use South. South allows to create migrations in Django models, instead of writing alter table ... South track the changes for you and apply it to the database. There's a good tutorial here http://south.readthedocs.org/en/latest/tutorial/part1.html

Anyway, if you are beginning with Django, in Django 1.7 the schema migrations are native to Django, you don´t need third party apps. It might be worth to check out https://docs.djangoproject.com/en/dev/topics/migrations/

fasouto
  • 4,386
  • 3
  • 30
  • 66
0

If the table doesn't have any important data or if you're just testing, you can just delete the table from the database. Then run python manage.py syncdb

sha256
  • 3,029
  • 1
  • 27
  • 32