Rémi Rémi - 10 months ago 238
MySQL Question

Django migrate django.db.utils.OperationalError: no such table:

Every time i try to migrate my DB in Django i get the following error:

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

However i do have the patients table in my models:

# Create your models here
class patients(models.Model):
first_name = models.CharField(max_length = 255)
last_name = models.CharField(max_length = 255)
dob = models.DateField(datetime.date.today)
gender = models.CharField(max_length = 1)
def __unicode__(self):
return self.id

Here is my views.py (where i think the error is):

from django.shortcuts import render
from rest_framework import viewsets
from api.models import patients
from api.serializers import PatientsSerializer
# Create your views here.

def home(request):
return render(request, 'index.html')

class PatientsViewSet(viewsets.ModelViewSet):
queryset = patients.objects.all()
serializer_class = PatientsSerializer

Answer Source

If you are running Windows it could be much simpler than that.

Before trying to migrate run >

Python manage.py makemigrations {name of the app where patients model is}

Meaning do specify the name of the app as an argument after makemigrations command.

I am not sure why, but Django migrations sometimes have this issue with migrations especially in Windows.