Strange behaviour - Case sensitive field inside form


I have noticed a strange behaviour with my project. I have created a class with different attributes

class basket (models.Model):
    pear=models.DecimalField(max_digits=25, decimal_places=20)
    Apple=models.DecimalField(max_digits=25, decimal_places=20)
    orange=models.DecimalField(max_digits=25, decimal_places=20)

then I created my form for this model

class basket_form(forms.ModelForm):
    class Meta:
        model = basket

Everything works fine, but I notice that I capitalized the attribute “Apple” and for a more consistent coding, I decided to change the case of the first letter of my attribute “Apple” everywhere in my code. Everything is fine, except this form.
I get a " KeyError at /" error message while loading the form.
if I capitalize again the attribute in the “exclude”, everything is working again.

I tried to delete the cache and redo the migration from scratch, still the same error.

I don’t really understand whats going on here, if anyone can help?

thank you,


You would need to change everything to be the appropriate case, then do a makemigrations, then run a migrate.

It’s possible that you may need to remove that field from your form temporarily, while you’re doing the makemigrations / migrate steps - I’m not sure of the degree of interactions there.


Thank’s a lot for the answer. Actually my mistake was really stupid… the field was in the exclude field list but populated in the method later on… so without the case typo, django was returning an error as the excluded field was trying to initialize…

Sorry for the post for such absent minded mistake.]