Ticket #11107: many_to_many.rel.through.diff
File many_to_many.rel.through.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/db/backends/postgresql/operations.py
121 121 style.SQL_TABLE(qn(model._meta.db_table)))) 122 122 break # Only one AutoField is allowed per model, so don't bother continuing. 123 123 for f in model._meta.many_to_many: 124 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 125 (style.SQL_KEYWORD('SELECT'), 126 style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), 127 style.SQL_FIELD(qn('id')), 128 style.SQL_FIELD(qn('id')), 129 style.SQL_KEYWORD('IS NOT'), 130 style.SQL_KEYWORD('FROM'), 131 style.SQL_TABLE(qn(f.m2m_db_table())))) 124 if not f.rel.through: 125 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 126 (style.SQL_KEYWORD('SELECT'), 127 style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), 128 style.SQL_FIELD(qn('id')), 129 style.SQL_FIELD(qn('id')), 130 style.SQL_KEYWORD('IS NOT'), 131 style.SQL_KEYWORD('FROM'), 132 style.SQL_TABLE(qn(f.m2m_db_table())))) 132 133 return output 133 134 134 135 def savepoint_create_sql(self, sid): -
django/db/backends/__init__.py
497 497 if not model._meta.managed: 498 498 continue 499 499 tables.add(model._meta.db_table) 500 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many ])500 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many if not f.rel.through]) 501 501 if only_existing: 502 502 tables = [t for t in tables if self.table_name_converter(t) in self.table_names()] 503 503 return tables