'Django GenericSitemap: Problem with the model

I'm trying to create a Django sitemap with the GenericSitemap function.

my urls.py file looks like this:

from django.urls import path
from . import views
from django.views.generic.base import TemplateView
from re_analytics.models_new import AnalyticsData
from django.contrib.sitemaps import GenericSitemap
from django.contrib.sitemaps.views import sitemap




sitemaps = {
    'analytics': GenericSitemap({
        'queryset': AnalyticsData.objects.all(),
        'date_field': 'timestamp',
    }, 
    priority=0.9)
}



urlpatterns = [
...

    path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),

]

My models_new.py file looks like this:

from django.db import models


class AnalyticsData(models.Model):
    index = models.TextField(blank=True, null=False)
    post_code = models.FloatField(blank=True, null=True)
...

Running the app works. I just have trouble accessing the sitemap view. I get the following error message:

OperationalError at /sitemap.xml
no such column: analytics_data.id
Request Method: GET
Request URL:    http://127.0.0.1:8000/sitemap.xml
Django Version: 3.2.5
Exception Type: OperationalError
Exception Value:    
no such column: analytics_data.id
Exception Location: /Users/finnj/coding/App1/env/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py, line 423, in execute
Python Executable:  /Users/finnj/coding/App1/env/bin/python
Python Version: 3.9.6
Python Path:    
['/Users/finnj/coding/re_crawler_homepage/re_homepage',
 '/opt/homebrew/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
 '/opt/homebrew/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
 '/opt/homebrew/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
 '/Users/finnj/coding/App1/env/lib/python3.9/site-packages']

This messages indicates that the column id is not existing in the model. And yes it is not existing there. The 'local var' in the error message indicate the the app is trying to extract this column :

sql 
('SELECT "analytics_data"."id", "analytics_data"."index", '
 '"analytics_data"."post_code",...

How does it happen that the id column suddenly appear? I do not use it at all.

Can somebody please help me? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source