#24513: "... has no field named None" with M2MField when migrating ---------------------------------+------------------------------------ Reporter: Kondou-ger | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 1.8rc1 Severity: Normal | Resolution: Keywords: migrations, bug | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+------------------------------------
Comment (by patrys): Not sure whether I'm on the right path but in `django/db/migrations/state.py` in `ProjectState.reload_model` the following happens: {{{ try: old_model = self.apps.get_model(app_label, model_name) except LookupError: related_models = set() else: # Get all relations to and from the old model before reloading, # as _meta.apps may change related_models = get_related_models_recursive(old_model) }}} The resulting set correctly contains all related m2m models. Later however this code is run: {{{ for rel_app_label, rel_model_name in related_models: try: model_state = self.models[rel_app_label, rel_model_name] except KeyError: pass else: states_to_be_rendered.append(model_state) }}} This lookup fails for all related m2m models which causes them not to appear in the to-be-rerendered state list. This in turn results in the m2m models pointing to the old (previously rendered) version of the altered class. I can trigger this problem quite reliably by having the migration first touch any non-m2m field of the affected class tree (which would cause all of the related models to be rendered) and then alter an m2m field (which fails m2m name lookups due to the relations pointing to out of date models). -- Ticket URL: <https://code.djangoproject.com/ticket/24513#comment:10> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.37c161bcd9cd6542cd25433ab6a98d08%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.