                          to_col1 = field.m2m_reverse_name()
                          opts = orig_field.opts
                          table2 = opts.db_table
                          from_col2 = field.m2m_column_name()
                          to_col2 = opts.pk.column
                          target = opts.pk
                          orig_opts._join_cache[name] = (table1, from_col1,
                                  to_col1, table2, from_col2, to_col2, opts,
                                  target)
  
 
</s> remove                         to_col2 = opts.pk.column
 </s> add                         to_col2 = opts.get_field_by_name(
                            field.m2m_reverse_target_field_name())[0].column </s> remove                         from_col1 = opts.pk.column
 </s> add                         from_col1 = opts.get_field_by_name(
                            field.m2m_reverse_target_field_name())[0].column </s> remove                         from_col1 = opts.pk.column
 </s> add                         from_col1 = opts.get_field_by_name(
                            field.m2m_target_field_name())[0].column </s> remove from models import Person, Group, Membership, UserMembership
 </s> add from models import (Person, Group, Membership, UserMembership,
                    Car, Driver, CarDriver)
                        to_col2 = opts.get_field_by_name(
                            field.m2m_target_field_name())[0].column
                          to_col1 = field.m2m_reverse_name()
                          opts = orig_field.opts
                          table2 = opts.db_table
                          from_col2 = field.m2m_column_name()
                        to_col2 = opts.get_field_by_name(
                            field.m2m_target_field_name())[0].column
                          target = opts.pk
                          orig_opts._join_cache[name] = (table1, from_col1,
                                  to_col1, table2, from_col2, to_col2, opts,
                                  target)
  
keep keep keep keep replace keep keep keep keep keep
 Fixed #15161 - Corrected handling of ManyToManyField with through table using to_field on its ForeignKeys. Thanks to adehnert for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15330 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/db/models/sql/query.py