[FIX] remove explicit naming of m2m indexes

Postgres has a limit of 63 characters on identifiers, because of the way
m2m index names are built the limit could relatively easily breached
leading to a truncation of the index name, and in some cases collisions
between the name of the two index.

<name> in CREATE INDEX is optional since Postgres 9.0, use this feature
instead of generating index names, should avoid any possible collision
on m2m index names.

closes #7620
fixes #2780 (master)
This commit is contained in:
Xavier Morel
2015-08-31 09:47:06 +02:00
parent 291cb7e3dd
commit 9aa82af4be
+2 -2
View File
@@ -2767,8 +2767,8 @@ class BaseModel(object):
if not cr.fetchall():
self._m2o_add_foreign_key_unchecked(m2m_tbl, col1, self, 'cascade')
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (m2m_tbl, col1, m2m_tbl, col1))
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (m2m_tbl, col2, m2m_tbl, col2))
cr.execute('CREATE INDEX ON "%s" ("%s")' % (m2m_tbl, col1))
cr.execute('CREATE INDEX ON "%s" ("%s")' % (m2m_tbl, col2))
cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (m2m_tbl, self._table, ref))
cr.commit()
_schema.debug("Create table '%s': m2m relation between '%s' and '%s'", m2m_tbl, self._table, ref)