[Answer]-Django write to database, IntegrityError

1👍

The solution was simple, albeit unexpected. I’m writing it up here in case anyone else runs into the same issue:

In addition to the summarized portion of the model I showed above, I was also trying to save an image with PIL (Python Imaging Library). Adding that to the relevant portion of the model shown above:

class Users(models.Model):
  user = models.ForeignKey(User, unique=True, null=True, blank=True)
  firstname = models.CharField(max_length=100, blank=True, default='')
  profile_pic = models.ImageField(upload_to='profilepics', max_length=300, default='')

This “upload_to” folder, “profilepics“, had the access permissions “755”, but when I changed them by running “$ chmod -R 777 profilepics” in the terminal, everything worked! Strange that the error message was blaming it on my the “user_id” field being null. It was really just a folder permission for something entirely different. Hope that helps somebody, someday.

Leave a comment