From a040f555069971192220122555f187530d679d53 Mon Sep 17 00:00:00 2001 From: Artyom Kotovskiy Date: Sun, 20 Apr 2025 18:17:47 -0400 Subject: Fixed #27489 -- Renamed permissions upon model renaming in migrations. Co-authored-by: Jacob Walls --- docs/releases/6.1.txt | 3 +++ docs/topics/auth/default.txt | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'docs') diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt index ef6ae1d424..d10225dfdf 100644 --- a/docs/releases/6.1.txt +++ b/docs/releases/6.1.txt @@ -123,6 +123,9 @@ Minor features * The default iteration count for the PBKDF2 password hasher is increased from 1,200,000 to 1,500,000. +* :attr:`.Permission.name` and :attr:`.Permission.codename` values are now + renamed when renaming models via a migration. + :mod:`django.contrib.contenttypes` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt index f9d216e1df..77888febb3 100644 --- a/docs/topics/auth/default.txt +++ b/docs/topics/auth/default.txt @@ -219,6 +219,18 @@ permissions for new models each time you run :djadmin:`manage.py migrate ` (the function that creates permissions is connected to the :data:`~django.db.models.signals.post_migrate` signal). +When a model is renamed in an installed application, Django automatically +updates the associated default permissions to match the new model name when +you run :djadmin:`manage.py migrate `. + +If a permission with the new codename already exists +(for example, due to a leftover permission from a previous migration), +Django raises an error with next steps. + +.. versionchanged:: 6.1 + + Updating permissions when models are renamed was added. + Assuming you have an application with an :attr:`~django.db.models.Options.app_label` ``foo`` and a model named ``Bar``, to test for basic permissions you should use: -- cgit v1.3