No such column error message
Question: I read the tutorial from the django site and now I hit the wall. It seems very
simple but it is giving me a problem. Everytime I run populate_rango.py script
I get an error.

I have modified my script and my models.py file based on the example from
Tango with Django site but still getting this not creating one of the column.

error :

    
    
        Starting Rango population script...
    Traceback (most recent call last):
      File "populate_rango.py", line 67, in <module>
        populate()
      File "populate_rango.py", line 8, in populate
        url="http://www.google.com")
      File "populate_rango.py", line 55, in add_page
        p = Page.objects.get_or_create(category=cat, title=title, url=url, likes=likes, views=views)[0]
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/django/db/models/manager.py", line 154, in get_or_create
        return self.get_queryset().get_or_create(**kwargs)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 376, in get_or_create
        return self.get(**lookup), False
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
        num = len(clone)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
        self._fetch_all()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
       self._result_cache = list(self.iterator())
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
        for row in compiler.results_iter():
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
        for rows in self.execute_sql(MULTI):
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
        cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/django/db/backends/util.py", line 69, in execute
        return super(CursorDebugWrapper, self).execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
        return self.cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
       six.reraise(dj_exc_type, dj_exc_value, traceback)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-         packages/django/db/backends/util.py", line 53, in execute
        return self.cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/django/db/backends/sqlite3/base.py", line 451, in execute
        return Database.Cursor.execute(self, query, params)
    django.db.utils.OperationalError: no such column: rango_page.likes
    

populate_rango.py

    
    
    import os
    def populate():
        search_cat = add_cat('Search Engins')
    
        add_page(cat=search_cat,
            title="Google",
            url="http://www.google.com")
    
         add_page(cat=search_cat,
            title="Yahoo !",
            url="http://www.yahoo.com")
    
        add_page(cat=search_cat,
            title="Bing",
            url="http://www.bing.com")
    
        social_cat = add_cat("Social Media")
    
        add_page(cat=social_cat,
            title="Facebook",
            url="http://www.facebook.com")
    
        add_page(cat=social_cat,
            title="LinkedIn",
            url="http://www.linkedin.com")     
    
        add_page(cat=social_cat,
            title="Twitter",
            url="http://www.twitter.com/")
    
        news_cat = add_cat("News Sites")
    
        add_page(cat=news_cat,
            title="CNN",
            url="http://www.cnn.com/")
    
        comme_cat = add_cat("Commerce")     
    
        add_page(cat=comme_cat,
            title="Amazon",
            url="http://www.amazon.com")
    
        add_page(cat=comme_cat,
            title="eBay",
            url="http://www.ebay.com")
    
        for c in Category.objects.all():
            for p in Page.objects.filter(category=c):
                print "- {0} - {1}".format(str(c), str(p))
    
    def add_page(cat, title, url, views=0, likes=0):
        p = Page.objects.get_or_create(category=cat, title=title, url=url, likes=likes, views=views)[0]
        return p
    
    def add_cat(name):
        c = Category.objects.get_or_create(name=name)[0]
        return c
    
    
    if __name__ == '__main__':
        print "Starting Rango population script..."
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tangorango.settings')
        from rango.models import Category, Page
        populate()
    

modes.py:

    
    
    from django.db import models
    
    class Category(models.Model):
        name = models.CharField(max_length=128, unique=True)
    
        def __unicode__(self):
            return self.name
    
    class Page(models.Model):
        category = models.ForeignKey(Category)
        title = models.CharField(max_length=128)
        url = models.URLField()
        likes = models.IntegerField(default=0)    
        views = models.IntegerField(default=0)
    
        def __unicode__(self):
            return self.title
    


Answer: run this command :

    
    
    python manage.py sqlall <your_app>
    

see the result , then if there wasn't `likes` table among them run this
command and add it manually :

    
    
    python manage.py dbshell
    

you can add it with this code:

    
    
    ALTER TABLE "Page" ADD COLUMN "likes" IntegerField(0)
    

**but note that sync db doesn't make integrate schema changes once the tables
are created. You have to delete the database manually and do syncdb again.**
for more information read
[THIS](https://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb) recipe
of `syncdb` in django site !

