diff --git a/django_mongodb/fields/auto.py b/django_mongodb/fields/auto.py index 229386126..7509d4b42 100644 --- a/django_mongodb/fields/auto.py +++ b/django_mongodb/fields/auto.py @@ -15,6 +15,14 @@ def __init__(self, *args, **kwargs): kwargs["db_column"] = "_id" super().__init__(*args, **kwargs) + def deconstruct(self): + name, path, args, kwargs = super().deconstruct() + if self.db_column == "_id": + del kwargs["db_column"] + if path.startswith("django_mongodb.fields.auto"): + path = path.replace("django_mongodb.fields.auto", "django_mongodb.fields") + return name, path, args, kwargs + def get_prep_value(self, value): if value is None: return None diff --git a/tests/model_fields_/test_autofield.py b/tests/model_fields_/test_autofield.py index 6c4345c4e..0013b2794 100644 --- a/tests/model_fields_/test_autofield.py +++ b/tests/model_fields_/test_autofield.py @@ -4,6 +4,13 @@ class MethodTests(SimpleTestCase): + def test_deconstruct(self): + field = ObjectIdAutoField() + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django_mongodb.fields.ObjectIdAutoField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {"primary_key": True}) + def test_to_python(self): f = ObjectIdAutoField() self.assertEqual(f.to_python("1"), 1)