Skip to main content

rename_permissions_after_model_rename

Updates Django permission codenames and names in the database after a model has been renamed during a migration. This function performs database I/O to modify permission records and raises a RuntimeError if it detects naming conflicts that cannot be resolved automatically.

def rename_permissions_after_model_rename(
app_config: AppConfig,
verbosity: int = 2,
plan: list = None,
using: str = DEFAULT_DB_ALIAS,
apps: Apps = global_apps,
stdout: file-like object = sys.stdout
)

Updates Django auth permission codenames and display names in the database after a model has been renamed via migrations. This function ensures that permission strings remain synchronized with the new model name to prevent broken access control logic.

Parameters

NameTypeDescription
app_configAppConfigThe configuration object for the Django application currently undergoing migration.
verbosityint = 2Controls the amount of notification messages printed to stdout; higher values provide more detailed logs of renamed permissions.
planlist = NoneA list of (migration, backward) tuples representing the migration plan used to identify RenameModel operations.
usingstr = DEFAULT_DB_ALIASThe database alias on which the permission updates should be performed.
appsApps = global_appsThe registry containing the models for the current application state.
stdoutfile-like object = sys.stdoutThe output stream where status messages and warnings are written.