-
Notifications
You must be signed in to change notification settings - Fork 0
How to Handle Non Nullable and Default Value
W. Bomar edited this page Oct 14, 2021
·
1 revision
You are trying to add a non-nullable field '...'
to choice without a default; we can't do that
(the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option:
- (blog post) What do you do when 'makemigrations' is telling you About your Lack of Default Value
- (video) You are trying to add a non-nullable field ' ' to ' ' without a default; we can't do that
Key to Icons
- ☑ Tested.
- ⚠ May be dangerous.
- ☑ Select option 1), then see:
- ⚠ Select option 1) and hope for the best.
- ☑ Select option 2) and provide a sensible default (not
None
a.k.a. null). - ⚠ (blog post) (hack) Add A Migration For A Non-Null Foreignkey Field In Django
If you permit Null
to be a default, then you may have this new error:
django.db.utils.IntegrityError: column "..." contains null values
- delete relevant migration files and rebuild migrations
- delete all migration files and rebuild migrations
If the field is cmsplugin_ptr
then know that
- it is a database relationship field managed automatically by Django,
- you may see it in workarounds for other plugins (source a, source b),
- you should not add or overwrite it unless you know what you are doing.
W. Bomar learned everything in the intitial version of this document after trying to overwrite cmsplugin_ptr
while extending its model from source a. His solution was delete all migration files and rebuild migrations.