For my basic, rudimentary Django CMS, in my effort to add a toggle feature to publish / unpublish a blog post (I’ve called my app ‘essays’ and the class object inside my models is is_published
), I’ve encountered an OperationalError when trying to use the Admin Dashboard to add essay content. I’m expecting to be able to switch a tick box to publish/unpublish but now I can’t even access the Dashboard.
Here is part of the traceback from my Django server:
File "/home/<user>/dev/projects/python/2018-and-2020/<projectdir>/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/<user>/dev/projects/python/2018-and-2020/<projectdir>/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: essays_essayarticle.is_published
The debug traceback reinforces the OperationalError above:
OperationalError at /admin/essays/essayarticle/
no such column: essays_essayarticle.is_published
Request Method: GET
Request URL: http://<DN>.ngrok.io/admin/essays/essayarticle/
Django Version:2.2.11
Exception Type: OperationalError
Exception Value:
no such column: essays_essayarticle.is_published
Exception Location:
/home/<user>/dev/projects/python/2018-and-2020/<projectdir>/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py in execute, line 383
Python Executable:
/home/<user>/dev/projects/python/2018-and-2020/<projectdir>/venv/bin/python
`Fri, 1 May 2020 19:37:31 +0000
Exception Value indicates ‘no such column’ which is a reference to my db. I’m running SQlite3 for test purposes. Prior to this OperationalError, I was troubleshooting issues with a DummyNode and "isinstance django.db.migrations.exceptions.NodeNotFoundError: Migration". The previous solution I arrived at was to delete my migrations in two of my apps. This SO answer is the particular solution that resolved the issue: https://stackoverflow.com/a/56195727/6095646
As per @Laila Buabbas's suggestion, to clarify, I deleted my migrations directory and invoked: python manage.py makemigrations app_name
for each of my two apps. So that previous SQLite issue has been resolved. But I can’t figure out this new OperationalError, described above.
Is the issue is with my views.py / models.py (copied below)? I can't narrow it down any more specific than that. Here is part of the class defined in my app’s models.py (with the new potential problem line added at the end):
class EssayArticle(models.Model):
title = models.CharField(max_length=256)
web_address = models.CharField(max_length=256)
web_address_slug = models.SlugField(blank=True, max_length=512)
content = models.TextField(blank=True)
is_published = models.BooleanField(default=True)
Here are the relevant lines from the applicable function in my views.py:
def article(request, web_address):
try:
article = EssayArticle.objects.get(
web_address_slug=web_address) # .filter(is_published=True)
except EssayArticle.DoesNotExist:
raise Http404('Article does not exist!')
context = {
'article': article,
}
return render(request, 'essays/article.html', context)
Commenting in our out the .filter(is_published=True)
doesn't stop or change the debug error.
My local dev box is Manjaro Linux with Django v2.2.11. I’m running Python v3.8.2.
Here are some of the resources I have already leveraged: