When you are using Django, recently you might be seeing the error ‘AttributeError: module ‘rest_framework.serializers’ has no attribute ‘NullBooleanField’.
Below is the snippet for error:
AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'
Issue is seen because of NullBooleanField has been depreciated from DRF (Django rest Framework) 3.14.0 version recently.
To fix the error, downgrade or use the DRF (Djangorestframework) version 3.13.1 using command djangorestframework = “3.13.1” rather version 3.14.0 and error would be fixed.
Change the DRF version from 3.14.0 to 3.13.1 using command djangorestframework = “^3.13.1” to djangorestframework = “3.13.1”.
Use the below command to fix the error:
djangorestframework = "^3.13.1" to djangorestframework = "3.13.1"
Issue is seen recently as Django 4.1 or latest versions are restricted from using Django Rest Framework due to NullBooleanField depreciation.
Issues have been raised on github and must be fix by team in next minor patch release.
You can track the issue on Issue1 Issue2 and use the DRF 3.13.1 version as a temporary fix for time being.
Conclusion
To fix the error AttributeError: module ‘rest_framework.serializers’ has no attribute ‘NullBooleanField’ downgrade or use the DRF (Djangorestframework) version 3.13.1 using command djangorestframework = “3.13.1” rather version 3.14.0 and error would be fixed.