diff --git a/README.rst b/README.rst index 2df1ad4..94999ff 100644 --- a/README.rst +++ b/README.rst @@ -141,6 +141,8 @@ Changes in version 1.1.0 ======================== * Added support for Django 2.1 and dropped support for Django < 1.11. +* `.save()`, `.create()`, etc. now raise IntegrityError if `null` is not True + and no default value was specified (like built-in fields do). Changes in version 1.0.0 ======================== diff --git a/src/picklefield/fields.py b/src/picklefield/fields.py index 968b66d..d4964ab 100644 --- a/src/picklefield/fields.py +++ b/src/picklefield/fields.py @@ -81,6 +81,7 @@ class PickledObjectField(models.Field): can still do lookups using None). This way, it is still possible to use the ``isnull`` lookup type correctly. """ + empty_strings_allowed = False def __init__(self, *args, **kwargs): self.compress = kwargs.pop('compress', False) diff --git a/src/picklefield/tests.py b/src/picklefield/tests.py index 78a9850..d3d4244 100644 --- a/src/picklefield/tests.py +++ b/src/picklefield/tests.py @@ -2,6 +2,7 @@ import json from datetime import date +import django.db from django.core import serializers from django.db import models from django.test import TestCase @@ -62,7 +63,7 @@ def testDataIntegrity(self): # Make sure the default value for default_pickled_field gets stored # correctly and that it isn't converted to a string. - model_test = TestingModel() + model_test = TestingModel(pickle_field=1, compressed_pickle_field=1) model_test.save() model_test = TestingModel.objects.get(id__exact=model_test.id) self.assertEqual((D1, S1, T1, L1), model_test.default_pickle_field) @@ -197,3 +198,7 @@ def testNoCopy(self): compressed_pickle_field='Copy Me', non_copying_field='Dont copy me' ) + + def testAllNonNullFieldsNeedToBeSetForSave(self): + with self.assertRaises(django.db.IntegrityError): + MinimalTestingModel.objects.create()