Search code examples
djangodjango-modelsdjango-viewsdjango-tables2

relation does not exist error when extending on simple django_tables2 tutorial example


I am trying to follow this relatively simple tutorial for django-tables2. the tutorial isn't comprehensive and so I am a little lost as to what is causing my error although I should note that it is from me attempted to extend upon the tutorial. I am a beginner at django so I am just trying to learn.

I am getting an error:

ProgrammingError at /table_test
relation "demo_query" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "demo_query"
                                      ^
Request Method: GET
Request URL:    http://127.0.0.1:8000/table_test
Django Version: 1.10.2
Exception Type: ProgrammingError
Exception Value:    
relation "demo_query" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "demo_query"
Exception Location:    C:\Users\zack\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py in execute, line 64

and my files are here:

http://pastebin.com/emhmbyxf


Solution

  • First of all, you should not instantiate your table in your tables.py like you do with table = QueryTable(data) on line 23. You should only do that when using the table in a view.

    I tried reproducing your error by creating a new Django environment, a new app and copying your files in. (demo/base.html was missing, some unrelated views in your view.py).

    I cannot reproduce the error though, just displays a table: https://github.com/jieter/django-tables2-so/blob/master/2016-12-09-120945_717x269_scrot.png.

    My code can be found on github.