首页 > 数据库 >ODOO里面的约束与PG数据库里面的约束

ODOO里面的约束与PG数据库里面的约束

时间:2022-08-15 10:56:22浏览次数:62  
标签:name constraint ir 约束 PG ODOO translation tc

一、odoo里面的约束写法

 

1、模型约束@api

    @api.constrains('parent_id')
    def _check_parent_id(self):
        if not self._check_recursion():
            raise ValidationError(_('You cannot create recursive departments.'))

 

2、sql约束

    _sql_constraints = [
        ('employee_token_unique', 'unique(employee_token)', 'Error: each employee token must be unique')
    ]

 

二、查找约束页面【设置--->技术--->模型约束】

 

 

 

 

三、PG数据库里面的约束

 

补充:PostgreSQL的依赖约束(系统表pg_depend和pg_constraint)详解

 

pg_depend是postgres的⼀张系统表,⽤来记录数据库对象之间的依赖关系,除了常见的主外键,还有其他⼀些内部依赖关系,可以通过这个系统表呈现出来。

 

一般数据库约束在odoo界面不能找到,常用操作是在数据库里面进行操作,命令如下:

--查找满足条件的约束
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name,
tc.is_deferrable,tc.initially_deferred
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = 'ir_translation';


-- 删除并插入约束
alter table ir_translation drop constraint if EXISTS ir_translation_lang_fkey_res_lang;

-- 删除约束
DROP INDEX ir_translation_unique;

--查找约束
select * from pg_indexes WHERE tablename='ir_translation';

--删除约束
DROP INDEX ir_translation_pkey;

--创建约束
CREATE INDEX ir_translation_unique;

 

标签:name,constraint,ir,约束,PG,ODOO,translation,tc
From: https://www.cnblogs.com/1314520xh/p/16587483.html

相关文章

  • orioledb pg 存储引擎
    orioledb是社区开发的一个新的pg存储引擎,主要是为了解决现在pg的一些问题,官方共享的一个ppt还是值得学习的(以下链接中)以下是一个简单的学习使用orioledb特性支持......
  • 蹉跎pg
    由于字段记录的内容超过规定or顶格长度。导致数据commit屡屡出错。智能化导致许多临界问题,由于急功近利,结果找不出原因,形成大把蹉跎时间。  记录至此,警醒提示。......