diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index d88cda6e20..06657ebaab 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -168,7 +168,7 @@ class FunctionTypeSerializer(BaseSerializer): ): klass = self.value.__self__ module = klass.__module__ - return "%s.%s.%s" % (module, klass.__name__, self.value.__name__), { + return "%s.%s.%s" % (module, klass.__qualname__, self.value.__name__), { "import %s" % module } # Further error checking diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index bef8f64061..5ee814d2af 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -211,6 +211,10 @@ class WriterTests(SimpleTestCase): X = "X", "X value" Y = "Y", "Y value" + @classmethod + def method(cls): + return cls.X + def safe_exec(self, string, value=None): d = {} try: @@ -468,6 +472,15 @@ class WriterTests(SimpleTestCase): ), ) + def test_serialize_nested_class_method(self): + self.assertSerializedResultEqual( + self.NestedChoices.method, + ( + "migrations.test_writer.WriterTests.NestedChoices.method", + {"import migrations.test_writer"}, + ), + ) + def test_serialize_uuid(self): self.assertSerializedEqual(uuid.uuid1()) self.assertSerializedEqual(uuid.uuid4())