Ticket #253 (closed defect: fixed)
ValueError for startmigration --auto on an app with a model with a relationship to a Proxy model.
| Reported by: | pmclanahan@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.6.2 |
| Component: | commands | Version: | 0.6 |
| Keywords: | proxy model | Cc: |
Description
I have an app for which I've successfully created an initial migration. This app contains a user profile model with a foreignkey relationship to a Proxy model for django.contrib.auth.models.User. This caused the initial migration to freeze the proxy model like so:
...
'main.gdfuser': {
'Meta': {'db_table': "'auth_user'"}
},
...
This appears to be insufficient for the subsequent startmigration commands to work out the auto migration as this is the result:
paul@frylock:~/Projects/gdfpups$ ./manage.py startmigration areas add_html_fields --auto
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 439, in execute_manager
utility.execute()
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 380, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/south/management/commands/startmigration.py", line 221, in handle
last_orm = migrations[-1].orm
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 62, in __get__
self.orm = FakeORM(*self._args)
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 45, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 109, in __init__
self.retry_failed_fields()
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 335, in retry_failed_fields
fname, modelname, e
ValueError: Cannot successfully create field 'user' for model 'userprofile': "The model 'user' from the app 'auth' is not available in this migration.".
The only modifications to the models in that app were to wholly unrelated models, and I only added a couple of fields.
I get similar results with either South 0.6 or the latest "stabelish" tag as of today.
Attachments
Change History
comment:1 Changed 2 years ago by andrew
- Status changed from new to closed
- Resolution set to fixed
- Milestone set to 0.6.2
comment:2 Changed 2 years ago by pmclanahan@…
The change does indeed prevent the freezing of proxy models, but it doesn't stop subsequent migrations from complaining about that model not being frozen. I believe the issue is that the startmigration command with the --auto option is looking for the proxied model to be frozen instead of the proxy model. Even with this fix the same ValueError? is raised:
paul@frylock:~/Projects/gdfpups$ ./manage.py startmigration areas add_html_fields --auto
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 439, in execute_manager
utility.execute()
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 380, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/paul/.local/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/south/management/commands/startmigration.py", line 221, in handle
last_orm = migrations[-1].orm
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 62, in __get__
self.orm = FakeORM(*self._args)
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 45, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 109, in __init__
self.retry_failed_fields()
File "/usr/local/lib/python2.6/dist-packages/south/orm.py", line 335, in retry_failed_fields
fname, modelname, e
ValueError: Cannot successfully create field 'user' for model 'userprofile': "The model 'user' from the app 'auth' is not available in this migration.".
I believe that the fix will be to freeze the model that was proxied, instead of skipping the freeze all together.
Thank you very much for your help!
comment:3 Changed 2 years ago by pmclanahan@…
I have confirmed that manually freezing "auth.user" into the initial migration is the fix. So the fix for this bug will be to make the automatic freezing process freeze the model to which the proxy points instead of the proxy model itself.
comment:4 Changed 2 years ago by andrew
Right, THAT bit is fixed in [a5d05ae21987].
Changed 2 years ago by pmclanahan@…
-
attachment
south_proxy_models_253.patch
added
Small cleanup of logic for less code repetition.
comment:5 Changed 2 years ago by pmclanahan@…
Excellent! Thanks Andrew!
If my understanding of your code is correct, I believe the patch I attached helps by reducing code repetition. I mainly wanted to just help in some way since you've been so helpful. It's not a useful change really, just a small restructure of what you did.
Thanks again.
Paul
comment:6 Changed 2 years ago by andrew
Yes, that's much cleaner. Applied in [771ee59d58fd].

Should be fixed in [a6218e55e742].