跳至内容
菜单
此问题已终结
2902 查看

This is from file openerp/addons/base/ir/ir_model.py, openerp 7.0, method _module_data_uninstall

        if typ == 'f':
            # test if FK exists on this table (it could be on a related m2m table, in which case we ignore it)
            cr.execute("""SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
                          WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""", ('f', name, model_obj._table))
            if cr.fetchone():
                cr.execute('ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_obj._table, name),)
                _logger.info('Dropped FK CONSTRAINT %s@%s', name, model)

        if typ == 'u':
            # test if constraint exists
            cr.execute("""SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
                          WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""", ('u', name, model_obj._table))
            if cr.fetchone():
                cr.execute('ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_obj._table, name),)
                _logger.info('Dropped CONSTRAINT %s@%s', name, model)

The code for typ == 'u' is identical to typ == 'f'.

Any particular reasons to have this distinction ?

形象
丢弃