0

When creating a new "Cast" record via the Django admin, I'm told "image_cover" attribute is null, but that attribute isn't even a part of the "Cast" model. Why would this happen?

The Error:

django.db.utils.IntegrityError: null value in column "image_cover" violates not-null constraint
DETAIL:  Failing row contains (33, 1, null).

Details

While "image_cover" is NOT part of the "Cast" model, it is a charfield on the "Book" model (foreign key). However the error occurs despite "image_cover" being null=True

I've tried...

I have not modified the Create function built into Django. and I have run makemigrations and migrate to ensure the database was up to date with models.py. And I have restarted my server to ensure the changes took effect.

Notice that the only value being reported as null in the failing row might be the "aliases" field despite the fact that I did define several alias objects as part of the "Cast" creation.

Here are the Models we are dealing with (models.py)

class Cast(models.Model):
    name = models.CharField(max_length=255, default='The Original Cast')
    book = models.ForeignKey('Book', on_delete=models.CASCADE)
    aliases = models.ManyToManyField('CharacterAlias', blank=True, related_name='casts')

class Book(models.Model):
    title = models.CharField(max_length=255, default='')
    author = models.CharField(max_length=255, default='')
    image_cover = models.CharField(max_length=1555, default='', blank=True, null=True)
    # some unrelated other stuff...
Michael Romrell
  • 1,026
  • 5
  • 15
  • 31
  • set **`null=True`**? **`image_cover = models.CharField(max_length=1555, default='', blank=True, null=True)`** – JPG Jun 11 '20 at 02:08
  • I tried that, even though setting a `null=True` on a charfield is not advised, unfortunately I got the same error. @ArakkalAbu – Michael Romrell Jun 11 '20 at 02:39

0 Answers0