Django.db.utils文件.IntegrityError“错误生成迁移”

2024-05-15 14:37:43 发布

您现在位置:Python中文网/ 问答频道 /正文

你知道吗django.db.utils文件.IntegrityError:主键为“1”的表“biblioteka\u book”中的行具有无效的外键:biblioteka_图书信息\u id包含的值“1”在biblioteka中没有对应的值_外部信息id是的

from django.db import models # Create your models here. class ExtraInfo(models.Model): OCENY = { (0, 'Nieznany'), (1, 'Słaba'), (2, 'Średnia'), (3, 'Dobra'), (4, 'Bardzo dobra'), (5, 'Arcydzieło') } ilosc_stron = models.IntegerField(default=0) ocena = models.IntegerField(default=0, choices=OCENY) class Book(models.Model): nazwa = models.CharField(max_length=60) opis = models.TextField() gatunek = models.CharField(max_length=30) cena = models.DecimalField(max_digits=400, decimal_places=2) wydanie = models.IntegerField(null=True, blank=True) autor = models.CharField(max_length=30) zdjecie = models.ImageField(null=True, blank=False, upload_to='Pictures') przecena = models.BooleanField() info = models.OneToOneField(ExtraInfo, on_delete=models.CASCADE, primary_key=True,) def __str__(self): return self.nazwa_with_wydanie() def nazwa_with_wydanie(self): return str(self.nazwa) + " (" + str(self.wydanie) + ")"

Tags: djangoself信息idtruedbmodelslength