diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py
index 1f2823b7919b4a9068cb8d5423387ac91c5c1387..0a38ccf03d4b82ad2660d96cf8975f0d3160f860 100644
--- a/openerp/osv/orm.py
+++ b/openerp/osv/orm.py
@@ -3387,7 +3387,8 @@ class BaseModel(object):
         m2m_tbl, col1, col2 = f._sql_names(self)
         # do not create relations for custom fields as they do not belong to a module
         # they will be automatically removed when dropping the corresponding ir.model.field
-        if not f.string.startswith('x_'):
+        # table name for custom relation all starts with x_, see __init__
+        if not m2m_tbl.startswith('x_'):
             self._save_relation_table(cr, m2m_tbl)
         cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (m2m_tbl,))
         if not cr.dictfetchall():