#23275 closed Bug (fixed)
Migrations - unmanaged models doesn't get autodetected
Reported by: | Mārtiņš Šulcs | Owned by: | Andrew Godwin |
---|---|---|---|
Component: | Migrations | Version: | 1.7-rc-2 |
Severity: | Release blocker | Keywords: | |
Cc: | cmawebsite@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Running migration with fk to unmanaged model fails with ValueError.
Models:
from django.db import models class SomeModel(models.Model): unmanaged_rel = models.OneToOneField('UnmanagedModel', null=True) class UnmanagedModel(models.Model): some_field = models.TextField() class Meta: managed = False
Autogenreated migration:
class Migration(migrations.Migration): dependencies = [ ] operations = [ migrations.CreateModel( name='SomeModel', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('unmanaged_rel', models.OneToOneField(null=True, to='testproj.UnmanagedModel')), ], options={ }, bases=(models.Model,), ), ]
Stacktrace:
Applying testproj.0001_initial...Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/martins/Projects/django-playground/django/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/home/martins/Projects/django-playground/django/django/core/management/__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/martins/Projects/django-playground/django/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/home/martins/Projects/django-playground/django/django/core/management/base.py", line 338, in execute output = self.handle(*args, **options) File "/home/martins/Projects/django-playground/django/django/core/management/commands/migrate.py", line 160, in handle executor.migrate(targets, plan, fake=options.get("fake", False)) File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 63, in migrate self.apply_migration(migration, fake=fake) File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 91, in apply_migration if self.detect_soft_applied(migration): File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 135, in detect_soft_applied apps = project_state.render() File "/home/martins/Projects/django-playground/django/django/db/migrations/state.py", line 89, in render model=lookup_model, ValueError: Lookup failed for model referenced by field testproj.SomeModel.unmanaged_rel: testproj.UnmanagedModel
Change History (8)
comment:1 by , 10 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 10 years ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
comment:3 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Yes, this does appear to be a serious issue.
Thanks.
comment:5 by , 10 years ago
Yeah, this is valid, the autodetector ignores unmanaged models. I'm pretty sure there's a reasonable fix, similar to the handling of proxy models.
comment:6 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
setting as unreviewed release blocker.