I have an “Images” model that has
imageID = models.IntegerField(primary_key=True, editable=False)
Then I’m doing:
newimage = Images(status=1, createDateTime=datetime.now(), User=user)
newimage.save()
Then I’m trying to retrieve the imageID using newimage.imageID, but it’s empty. Even after the row was added to the database.
Any ideas?
You’ve used an
IntegerField, rather than anAutoField, which implies that you’re responsible for setting the value yourself rather than letting the database do it. Do you have any such code? If not, why have you used that field? Why not just use the automatic id field?