pythondjangodjango-rest-framework

django.db.utils.OperationalError: no such table: django_site_id_seq


I got this error when running command python manage.py test for testing purpose. I tried after delete my pycache and migration files and db.sqlite3 then run the python manage.py makemigrations and python manage.py migrate again as well.

But still got the same error...

Here is my test.py

from rest_framework.test import APITestCase
from django.urls import reverse
from rest_framework import status

# Create your tests here.

class UserTest(APITestCase):

    def setUp(self):
        register_url = reverse('user:register')
        data = {
            "username":"Tester",
            "email":"tester@gmail.com",
            "password":"tester123",
            "mobile_number":"03322917356"
        }

        self.client.post(register_url, data, format='json')


    def test_user_can_register(self):
        register_url = reverse('user:register')
        data = {
            "username":"Tester1",
            "email":"tester1@gmail.com",
            "password":"tester123",
            "mobile_number":"03322911356"
        }
        response = self.clent.post(register_url , data , format='json')
        self.assertEqual(response.status_code ,status.HTTP_201_CREATED)

Solution

  • Try switching to postgresql, to see if it is a database issue always good to try something else. if that doesn’t work then I would get an existing example that does work and compare it from there to what you have. tbh unless you have your code opensource it is difficult to debug something like this without speculation as a lot of different systems are affected when ensuring migrations are applied. Check your migrations files to see if those are indeed correct. they should be under /migrations