一、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