Steps to reproduce:
1. Create a new model
{{{
class AwesomeModel(models.Model):
class Meta:
verbose_name = "My awesome model"
}}}
2. Run "makemigrations" and than "migrate"
3. Look at the generated permissions
{{{
select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my awesome model | 2 |
add_awesomemodel
2 | Can change my awesome model | 2 |
change_awesomemodel
3 | Can delete my awesome model | 2 |
delete_awesomemodel
}}}
4. Change the "verbose_name" of the Meta class of the model
{{{
class AwesomeModel(models.Model):
class Meta:
verbose_name = "My really awesome model"
}}}
5. Run "makemigrations" and than "migrate" again
6. Look at the generated permissions agaun
{{{
select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my awesome model | 2 |
add_awesomemodel
2 | Can change my awesome model | 2 |
change_awesomemodel
3 | Can delete my awesome model | 2 |
delete_awesomemodel
}}}
As you can see the names of the model's permissions are not changed.
But! If now you drop the database and apply all the migrations to the
empty database - the permissions will have correct names
{{{
select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my really awesome model | 2 |
add_awesomemodel
2 | Can change really my awesome model | 2 |
change_awesomemodel
3 | Can delete really my awesome model | 2 |
delete_awesomemodel
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26756>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
New description:
Steps to reproduce:
{{{
2 | Can change my really awesome model | 2 |
change_awesomemodel
3 | Can delete my really awesome model | 2 |
delete_awesomemodel
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:1>
* version: 1.9 => master
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:2>
* owner: nobody => black3r
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:3>
* has_patch: 0 => 1
Comment:
I've tried to implement this in the management command, that handles
creating non-existing permissions after migrating an app.
Here's a PR https://github.com/django/django/pull/6778
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:4>
* needs_better_patch: 0 => 1
Comment:
I left a comment for improvement on the PR. Also tests are needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:5>
Comment (by black3r):
I've tried the suggested injecting a migration operation approach, but
somehow ended up with an unexpected exception saying Permission model
cannot resolve 'content_type' into a field.
then i've tried optimizing my previous approach by only checking
permissions for models that had verbose_name altered during the migration.
that should be almost as effective as the suggested approach, and passed
the test I've written, so I created a new PR (
https://github.com/django/django/pull/6837 ) for that approach.
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:6>
* component: Migrations => contrib.auth
Comment:
#27489 "Renaming a model doesn't rename the permission name and codename"
is a related issue that would be useful to work on while in this area.
--
Ticket URL: <https://code.djangoproject.com/ticket/26756#comment:7>