简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM