| 5 | | I think 1. is safer but I am open to suggestions. |
| | 3 | 1. Create model 'RegularThenProxyModel' |
| | 4 | |
| | 5 | {{{ |
| | 6 | +----------------------------------+---------------------------+-----------------------+ |
| | 7 | | name | codename | model | |
| | 8 | +----------------------------------+---------------------------+-----------------------+ |
| | 9 | | Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel | |
| | 10 | +----------------------------------+---------------------------+-----------------------+ |
| | 11 | }}} |
| | 12 | |
| | 13 | 2. Migrate |
| | 14 | 3. Delete the model called 'RegularThenProxyModel' |
| | 15 | 4. Add a new proxy model called 'RegularThenProxyModel' |
| | 16 | |
| | 17 | {{{ |
| | 18 | +----------------------------------+---------------------------+-----------------------+ |
| | 19 | | name | codename | model | |
| | 20 | +----------------------------------+---------------------------+-----------------------+ |
| | 21 | | Can add concrete model | add_concretemodel | concretemodel | |
| | 22 | | Can add regular then proxy model | add_regularthenproxymodel | concretemodel | |
| | 23 | | Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel | |
| | 24 | +----------------------------------+---------------------------+-----------------------+ |
| | 25 | }}} |
| | 26 | |
| | 27 | What happens when creating a proxy model right away: |
| | 28 | |
| | 29 | 1. Create a proxy model 'RegularThenProxyModel' |
| | 30 | {{{ |
| | 31 | +----------------------------------+---------------------------+---------------+ |
| | 32 | | name | codename | model | |
| | 33 | +----------------------------------+---------------------------+---------------+ |
| | 34 | | Can add concrete model | add_concretemodel | concretemodel | |
| | 35 | | Can add regular then proxy model | add_regularthenproxymodel | concretemodel | |
| | 36 | +----------------------------------+---------------------------+---------------+ |
| | 37 | }}} |
| | 38 | |
| | 39 | As you can see, the problem here is that permissions are not cleaned up, so we are left with an existing `| Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel |` row. When the 2.2 migration is applied, it tries to create that exact same row, hence the `IntegrityError`. Unfortunately, there is no `remove_stale_permission` management command like the one for `ContentType`. So I think we can do the following: |
| | 40 | |
| | 41 | 1. Show a nice error message to let the user delete the conflicting migration |
| | 42 | 2. Re-use the existing permission |
| | 43 | |
| | 44 | I think 1. is much safer as it will force users to use a new permission and assign it accordingly to users/groups. |
| | 45 | |
| | 46 | **Edit**: ''I revised my initial comment after reproducing the error in my environment.'' |