I created my models and everything was running smooth, but I had to create another field, so I created it and added it in the model definition. After that (I'm not 100% it was that the cause) Django's admin tries to ADD the NULL value in the ID field.
Initial model:
class Image(models.Model):
setid = models.ForeignKey(Imageset, null=False)
originalwidth = models.PositiveIntegerField(editable=False)
originalheight = models.PositiveIntegerField(editable=False)
originalimage = models.ImageField('Imagem', upload_to=image_upload_to, height_field='originalheight', width_field='originalwidth')
alt = models.CharField('Alt', max_length=128, help_text='ALT da imagem', null=False, blank=False)
(removed from brevity...)
def save(self):
super(Image, self).save()
self.create_thumbnail()
Then I added this field
thumbnail = models.ImageField(max_length=128, null=True, editable=False, upload_to=True)
And added manually the thumbnail field in the Database.
Admin is working really fine for UPDATES, but It's refusing to ADD new records.
The error is "Violation of non-null constraint". DETAIL: Failing row contains (null, 1, 700, 701, f/3/f3d4357f7c697aa08dc65f7d866cc30d_14.jpg, ddd, , )
.
The method create_thumbnail is fine, i just removed it, removed the custom save and nothing seems to work.
According to that message, Django is trying to run something like this:
INSERT INTO "public"."imageset_image" ("id","setid_id","originalwidth","originalheight","originalimage","alt")
VALUES (null, 1, 999, 999, 'a/4/a49ba4fc8cbc32f760cb51d84cf9d0cc.jpg', 'alt')
wich is kinda silly and produces the same error. But, when I try to do the right SQL
INSERT INTO "public"."imageset_image" ("setid_id","originalwidth","originalheight","originalimage","alt")
VALUES (1, 999, 999, 'a/4/a49ba4fc8cbc32f760cb51d84cf9d0cc.jpg', 'alt')
ERROR Again.
Seems that for some reason Postgresql forgot the SERIAL even though they are there
SELECT * FROM information_schema.sequences WHERE sequence_catalog='catalogname' AND sequence_schema='public' AND sequence_name='imageset_image_id_seq'
Any ideas? It was working fine, I added several records..... thanks in advance