不断收到此错误{关系“ profiles_user”不存在}

时间:2020-04-19 16:29:57

标签: python django postgresql

我是一名初学者程序员,致力于我自己的Django项目。每当创建用户时,我都试图使模型自行创建。但我一直收到此错误{关系“ profiles_user”不存在}。 我正在使用PostgreSQL作为数据库。顺便说一句,当我尝试迁移数据时会发生此错误

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models.signals import post_save

class User(AbstractUser):
    is_expert = models.BooleanField(default=False)
    is_student = models.BooleanField(default=False)







EDUCATION=(
    ('Collage','Collage'),
    ('Post_Graduate','Post_Graduate'),
    ('Masters','Masters'),
    ('PHD','PHD'),
)


class Expert(models.Model):
    expert = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    first_name = models.CharField(max_length=12, null=True, default='')
    last_name = models.CharField(max_length=20, null=True)
    discription = models.TextField(null=True)
    education = models.CharField(max_length=200, choices=EDUCATION,  null=True)
    field = models.CharField(max_length=200, null=True)
    company = models.CharField(max_length=50,null=True)
    position = models.CharField(max_length=20, null=True)
    experience = models.TextField(null=True)
    charge_per_hour = models.IntegerField(default="0")

    def __str__(self):
        return (f'{self.first_name} {self.last_name}')



def create_profile(sender,**kwargs ):
    if kwargs['created']:
        user_profile=Expert.objects.create(expert=kwargs['instance'])


post_save.connect(create_profile,sender=User)

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

我似乎需要专门自行迁移该应用。

python manage.py makemigrations profiles
python manage.py migrate profiles