I am new to Django and trying to create a Profile(Patient) model. Here are my models.
from django.db import models
from django.contrib.auth.models import User
class Patient(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
age = models.PositiveSmallIntegerField()
gender = models.CharField(max_length=1)
def __str__(self):
return str(self.user.username)
class Doctor(models.Model):
name = models.CharField(max_length=50)
max_slots = models.PositiveIntegerField(default=10)
available = models.PositiveIntegerField(default=0)
def __str__(self):
return str(self.name)
class Assistant(models.Model):
name = models.CharField(max_length=50)
docid = models.OneToOneField('Doctor', on_delete=models.CASCADE)
def __str__(self):
return str(self.name)
class Appointment(models.Model):
confirmed = models.BooleanField(default=False)
patid = models.OneToOneField('Patient', on_delete=models.CASCADE)
docid = models.ForeignKey('Doctor', on_delete=models.CASCADE)
assid = models.ForeignKey('Assistant', on_delete=models.CASCADE)
def __str__(self):
return str(self.patid)
Last migration file
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('doctor', '0014_auto_20200318_0219'),
]
operations = [
migrations.AlterField(
model_name='patient',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
and error I am getting when I run migrations
Operations to perform:
Apply all migrations: admin, auth, contenttypes, doctor, sessions
Running migrations:
Applying doctor.0011_auto_20200318_0211...Traceback (most recent call last):
File "C:\Users\syd's\.virtualenvs\django-hospital-0gp1XnhJ\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "doctor_patient" does not exist
I tried dropping all my tables and running migrations again but no use.
P.S. The name of my Django app is "doctor" and I am using PostgreSQL. I have ran an initial migration with "username" as a CharField then decided to use the User model as a OneToOneField.