Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'NOT NULL constraint failed' after adding to models.py

I'm using userena and after adding the following line to my models.py

zipcode = models.IntegerField(_('zipcode'),                                    max_length=5) 

I get the following error after I hit the submit button on th signup form:

IntegrityError at /accounts/signup/ NOT NULL constraint failed: accounts_myprofile.zipcode 

My question is what does this error mean, and is this related to Userena?

like image 322
stephan Avatar asked Sep 21 '14 21:09

stephan


People also ask

How do I fix not null constraint failed?

utils. IntegrityError: NOT NULL constraint failed. Go to the migrations folder and delete manually files that have 000*_lastAction_blah-blah type of name, you can delete, probably all, but 0001_initial.py file. After that run ./manage.py make migrations app_you_are_updateing, it should update your database.

What is not null constraint failed?

By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.


1 Answers

You must create a migration, where you will specify default value for a new field, since you don't want it to be null. If null is not required, simply add null=True and create and run migration.

like image 173
coldmind Avatar answered Sep 28 '22 02:09

coldmind