I\'m currently following http://www.tangowithdjango.com and I\'m trying to populate an existing DB with populate_rango.py. When I create the new categories, I\'m tr
The following worked for me. I have no idea whether it will cause issues in later chapters, but it allowed the populate_rango.py script to run.
Changes to populate_rango.py
def populate():
python_cat = add_cat("Python", views=128, likes=64)
django_cat = add_cat("Django", views=64, likes=32)
frame_cat = add_cat("Other Frameworks", views=32, likes=16)
and
def add_cat(name, views=0, likes=0):
c = Category.objects.get_or_create(name=name, views=views, likes=likes)[0]
return c
That resulted in a database IntegrityError so I edited the View fields in my Category and Page classes to ensure they aren't unique:
Changes to models.py
class Category(models.Model):
views = models.IntegerField(default=0, unique=False)
class Page(models.Model):
views = models.IntegerField(default=0, unique=False)
Finally, I deleted the database and ran
python manage.py syncdb
and
python populate_rango.py