#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):
I believe I have tracked it down further:
In `django/db/backends/sqlite3/schema.py` line 234 (`_alter_many_to_many`)
we have:
{{{
override_uniques=(new_field.m2m_field_name(),
new_field.m2m_reverse_field_name())
}}}
However `new_field.m2m_field_name()` return `None`.
`new_field.m2m_field_name()` is a partial that evaluates to
`self._get_m2m_attr(related, 'name')` where `related` is a class the
relation is pointing to.
The implementation lives in `django/db/models/fields/related.py` line 2470
(`_get_m2m_attr`):
{{{
for f in self.rel.through._meta.fields:
if (f.is_relation and f.rel.to == related.related_model and
(link_field_name is None or link_field_name == f.name)):
}}}
However at this point `f.rel.to` and `related` point to two different
classes that are not considered equal. This could be caused by the fact
that the operation is an `AlterField` and it creates two states of the
affected class—one before and one after the migration—even though all of
the changes happen in a separate m2m model.
--
Ticket URL: <https://code.djangoproject.com/ticket/24513#comment:9>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.30b7030e00712676ef01baa2db239997%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.