sqlite3.OperationalError: no such table: blog_category

Hello,

I made a django project and would like to deploy it on pythonanywhere, but I got the next issue and I don’t know how to solve it. Can somebody help me?

This is the error:

Traceback (most recent call last):

  File "/home/Livcamp/.virtualenvs/livcamp.pythonanywhere.com/lib/python3.8/site-packages/django/db/back
ends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/Livcamp/.virtualenvs/livcamp.pythonanywhere.com/lib/python3.8/site-packages/django/db/back
ends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
sqlite3.OperationalError: no such table: blog_category

This is my code models.py

from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils import timezone
# from ckeditor.fields import RichTextField

# Create your models here.
class Category(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(null=True)
    title_tag = models.CharField(max_length=255, default='Livcamp')
    meta_tag = models.CharField(max_length=255, default='')
    keyword = models.CharField(max_length=255, default='Livcamp')

    def __str__(self):
        return self.name
    
    def get_absolute_url(self):
        return reverse("add_category")

My settings code:

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}

Do I need to share more of my code?

I hope somebody can help me out.

Did you run the manage.py migrate command on that database? (I have no idea how to do that for that environment.)

Hi KenWhitesell, yes I did the ‘python manage.py makemigrations’ and ‘python manage.py migrate’ command.

The project is running succefully on my local machine. But when I upload it to pythonanywhere I got the error.

Are you uploading your database as part of your project?

If not, then you need to run the migrate command for the database on the server, not your local copy.

Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

(I’ve taken the liberty of adjusting your original post.)

1 Like

I did that too, but doesn’t change anything… :thinking:

Hi, perhapse, you have already tried that, but in any case your can try to make migrations only for your app name:

python3 manage.py makemigrations appName
python3 manage.py migrate appName

  • appName is your app name

This solution has helped me in the past.

Hi pavelsmirnov, thanks for the idea. Unfortunately it didn’t work…

If the data in your SQLite database has no value for you now (if you are not afraid of losing your data), you can do the following steps:

  1. Delete your database;

  2. Delete all migrations in your app folder (but don’t delete init file);

  3. And then make migrations again:

python3 manage.py makemigrations
python3 manage.py migrate

Hope that will help.

Thanks for your help! I got some help from a python-django developer and it is fixed now :slight_smile: