Skip to content
Advertisement

Tango with Django (v1.9/1.10) – Chapter 5, populate_rango issues

I will try to be concise. The background for this issue is that I’m familiar with Python, however I am BRAND NEW to django. This book is my first exposure to it and I’ve come to find the more I work through the book that online Q/A’s for django are not very general, thus making it harder to “just google it” and find an answer.

    MY ENVIRONMENT

Resource: Tango with Django (for version 1.9/1.10)
Distro: Elementary OS, Patched to the latest
Python Version: 3.5
Django Version: 1.11.x

    MY PROBLEM

What Is my Error: django.core.exceptions.FieldError
What are the Details: Invalid field name(s) for model Page: ‘category’.
What does the Error mean?: Per The Docs, This error is raised when there is a problem with a field inside a model..Of the reasons listed The following look relevant to my issue:

  • An infinite loop is caused by ordering.
  • I have verified the the order in which the fields are declared in the model is consistent with how the add_page. as well, I have debugged my code and see that all the fields appear to be correct as they pass through the various functions. however I’m thinking perhaps [this] is might be the issue. I think the work ‘category’ is somehow referencing the category class? total troubleshooting conjecture.
  • A Feild name is invalid
  • It’s always something simple, I’ve checked this out and the naming and usage of variables is consistent throughout the code. I’ve also double checked my code against the book. Everything seems in order, the code just isn’t working.

    The Traceback

    JavaScript

    populate_rango.py

    JavaScript

    models.py

    JavaScript

    for what it’s worth, this issue persists even if I rebuild the database. (rm app.db, makemigrations, migrate)

    Advertisement

    Answer

    JavaScript

    Variable names are case sensitive – this includes field names and other class attributes. Change Category = models.ForeignKey(Category) to category = models.ForeignKey(Category) to fit model coding style then rebuild your db tables and you should be ok to do Page.objects.get_or_create(category=cat...

    User contributions licensed under: CC BY-SA
    6 People found this is helpful
    Advertisement