Im new in Django and I can\'t figure out this error. Help please. It gave TypeError - save() got an unexpected keyword argument \'force_insert\'. I tested the code below and
When you are overriding model's save method in Django, you should also pass *args
and **kwargs
to overridden method. this code may work fine:
def save(self, *args, **kwargs):
super(Profile, self).save(*args, **kwargs)
img = Image.open(self.image.path)
if img.height > 300 or img.width > 300:
output_size = (300,300)
img.thumbnail(output_size)
img.save(self.image.path)'
I had the same problem.
This will fix it:
Edit the super method in your users/models.py file:
def save(self, *args, **kwargs):
super.save(*args, **kwargs)
You've overridden the save method, but you haven't preserved its signature. Yo need to accept the same arguments as the original method, and pass them in when calling super.
def save(self, *args, **kwargs):
super().save((*args, **kwargs)
...
I was looking for this error on Google and found this topic. This code solved my problem in Python 3:
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
super().save(force_insert, force_update, using, update_fields)
Django 3.0
and Python 3.8
.Django models.Model source code.