当我尝试创建超级用户
python manage.py createsuperuser
我收到以下错误
django.db.utils.IntegrityError: NOT NULL constraint failed: me_teacher.subject_id
我/模特
from django.conf import settings
from django.contrib.auth.models import User, AbstractUser
from django.db import models
import sys
sys.path.append('../')
from wisdom.models import Subject
class Teacher(AbstractUser):
name = models.CharField(max_length=20)
surname = models.CharField(max_length=20)
user = models.OneToOneField(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
subject = models.ForeignKey(Subject, related_name='teacher_subject',
on_delete=models.CASCADE)
智慧/模型
from django.db import models
class Subject(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True)
class Meta:
ordering = ['title']
def __str__(self):
return self.title
我的问题是什么?
有必要提供创建用户而不被绑定到主题的能力 (
null=True
)