Django issue with adding instances to a class
Question: The code below this compiles, but whenever I uncomment purchase_date,
po_number, or confirmed it's giving me an error. I tried python manage.py
syncdb after uncommenting those lines and it's stil giving me errors.

    
    
    from django.db import models
    
    
    class PurchaseOrder(models.Model):
    
           product = models.CharField(max_length=256)
           vendor = models.CharField(max_length=256)
           price = models.FloatField()
           item_number = models.AutoField(primary_key=True)
        #  purchase_date = models.DateField()
        #  po_number = models.IntegerField(unique=True)
        #  confirmed = models.NullBooleanField(null=True)
    

The error I am getting is this:

    
    
    DatabaseError at /admin/purchaseorders/purchaseorder/
    column purchaseorders_purchaseorder.purchase_date does not exist
    LINE 1: ...e", "purchaseorders_purchaseorder"."item_number", "purchaseo...
                                                                 ^
    Request Method: GET
    Request URL:    
    Django Version: 1.5.1
    Exception Type: DatabaseError
    Exception Value:    
    column purchaseorders_purchaseorder.purchase_date does not exist
    LINE 1: ...e", "purchaseorders_purchaseorder"."item_number", "purchaseo...
                                                                 ^
    Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 54
    Python Executable:  /usr/bin/python
    Python Version: 2.7.3
    Python Path:    
    ['/LPG/firstproject',
     '/usr/lib/python2.7',
     '/usr/lib/python2.7/plat-linux2',
     '/usr/lib/python2.7/lib-tk',
     '/usr/lib/python2.7/lib-old',
     '/usr/lib/python2.7/lib-dynload',
     '/usr/local/lib/python2.7/dist-packages',
     '/usr/lib/python2.7/dist-packages']
    Server time:    Tue, 23 Jul 2013 16:30:58 +0000
    

Does this have anything to do with tables already being created and it wants
me to clear them?


Answer: While syncdb would work for creating new tables, it does not work for altering
database tables. In this case, it looks like you added the 3 columns after
running syncdb once.

Here is [the documentation](https://docs.djangoproject.com/en/dev/ref/django-
admin/#syncdb) (Readup on : Syncdb will not alter existing tables)

To achieve this, you can do it in 2 ways:

  1. you would need a 3rd party application such as [django south](http://south.aeracode.org/) which would handle the migrations for you. Once you run the migrations, you would be able to access these columns without any issue. (Highly recommended) 

  2. If your code is not in production yet, you can just drop the database and then do `syncdb` (a fresh start) - This is not very recommended - as it might be a good idea to use south. 

Here is a [step by step tutorial](http://www.djangopro.com/2011/01/django-
database-migration-tool-south-explained/) on south, and here is the [official
documentation on south](http://south.aeracode.org/wiki/Tutorial1)

