I struggled with this issue for proxy models as well. I had a model A
and a proxy model B
. For some decisions I had to refactor the name of model A
to model C
, then when I run the migrations nothing worked. The reason is the next:
- When you create your migrations using
manage.py makemigrations
on a proxy model the migration file is something like this:
migrations.CreateModel(
name='BProxy',
fields=[
],
options={
'proxy': True,
'indexes': [],
'constraints': [],
},
bases=('app_name.database_table_name_of_a',),
),
more on this.
If you see the bases
line doesn't refer to the python model but the database table, so in my case that created and issue . So the solution:
- Create and empty migration and delete the proxy model
operations = [
migrations.DeleteModel(
name='PythonProxyModelClassName',
),
- Run again
python manage.py makemigrations
.
This have the advantage of keeping your migrations history clean so if you are working on different environments it will be easier to maintain them.
disclaimer: I haven't manually check if the permissions
model configuration gets affected by this, but after running tests with database construction it seams it doesn´t.
contrib.auth
before, it didn't work otherwise. – Tented