我无法添加新用户只是说外键约束失败我不知道为什么。我不知道哪个外键被侵犯了,为什么会被侵犯。 这是我的models.py:
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
def user_avatar_path(instance, filename):
return 'user_{0}/avatar/{1}'.format(instance.id, filename)
class board(models.Model):
name = models.CharField(max_length=20)
def __str__(self):
return (self.name)
class User(AbstractUser):
boards = models.ManyToManyField(
board, through='board_member', related_name="members")
def __str__(self):
return self.username
class list(models.Model):
title = models.CharField(max_length=20)
board = models.ForeignKey(
board, related_name="lists", on_delete=models.CASCADE)
class board_member(models.Model):
User = models.ForeignKey(
User, related_name="memberships", on_delete=models.CASCADE)
board = models.ForeignKey(
board, related_name="memberships", on_delete=models.CASCADE)
access = models.CharField(max_length=20)
def __str__(self):
return ("%s is %s in board %s" % (self.user, self.access, self.board))
class card(models.Model):
list = models.ForeignKey(list, related_name="cards",
on_delete=models.CASCADE)
text = models.CharField(max_length=100)
date = models.DateField(auto_now=True)
due = models.DateField()
flag = models.CharField(max_length=20)
有人可以帮我吗?