I’m on Django==5.2.12 and django-imagekit==6.1.0
This is my PostImage model:
class PostImage(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, related_name="images")
image = ProcessedImageField(verbose_name=_("image"), storage=post_image_storage, upload_to=upload_to_post_image_directory, width_field="width", height_field="height", blank=False, null=True, format="JPEG", options={"quality": 100}, processors=[ResizeToFit(width=1024, upscale=False)])
width = models.PositiveIntegerField(editable=False, null=False, blank=False)
height = models.PositiveIntegerField(editable=False, null=False, blank=False)
hash = models.CharField(_("hash"), max_length=64, blank=False, null=True)
thumbnail = ProcessedImageField(verbose_name=_("thumbnail"), storage=post_image_storage, upload_to=upload_to_post_image_directory, blank=False, null=True, format="JPEG", options={"quality": 50}, processors=[ResizeToFit(width=1024, upscale=False)])
media = GenericRelation(PostMedia)
image_view_type = (
("regularimage", "regularimage"),
("gridimages", "gridimages"),
viewtype = models.CharField(max_length=24, choices=image_view_type, default="")
While create a PostImage object, I get thrown the error.
null value in column “width” violates not null constraint.
Since I require the width and height fields to be calculated for further processing,
I don’t want to change the fields width and height with null=True. However, just to check what happens after doing it, i did try specifying null=True. The PostImage object does get created but with no values for width and height.
Detailed trace:
django.db.utils.IntegrityError: null value in column "width" of relation "myapi_posts_postimage" violates not-null constraint
my-api-webserver-0 | DETAIL: Failing row contains (1, posts/9957dc49-639b-490e-87f5-54cab35c0229/582a8f62-86d5-4c3d-a1..., null, null, 01d2d1ce86aa7007f1cecad2259394163b95987a850e6c2d6a48c322a2dc8df0, posts/9957dc49-639b-490e-87f5-54cab35c0229/33d944aa-ded1-49cb-a9..., regularimage, 1).
Haven’t been able to get a response on stack overflow yet. This is driving me nuts.