-- 移除 adm_practitioner 表中 create_by 列的 NOT NULL 约束 -- 用于解决 org.postgresql.util.PSQLException: ERROR: null value in column "create_by" of relation "adm_practitioner" violates not-null constraint -- 在PostgreSQL中,NOT NULL约束实际上是列的一个属性,而不是命名约束 -- 因此我们使用 ALTER COLUMN ... DROP NOT NULL 来移除它 -- 可选:先查看当前表结构及约束信息 -- 注意:\d 命令仅在 psql 中有效,在脚本中不能使用 /* SELECT c.column_name, c.is_nullable, c.data_type, tc.constraint_type FROM information_schema.columns c LEFT JOIN information_schema.constraint_column_usage ccu ON c.column_name = ccu.column_name AND c.table_name = ccu.table_name LEFT JOIN information_schema.table_constraints tc ON ccu.constraint_name = tc.constraint_name WHERE c.table_name = 'adm_practitioner' AND c.column_name = 'create_by'; */ -- 移除 create_by 列的 NOT NULL 约束 ALTER TABLE "public"."adm_practitioner" ALTER COLUMN "create_by" DROP NOT NULL; -- 可选:如果需要,可以同时移除默认值 -- ALTER TABLE "public"."adm_practitioner" -- ALTER COLUMN "create_by" DROP DEFAULT; -- 提示:执行此脚本后,create_by 列将允许 NULL 值 -- 这将解决插入数据时因缺少 create_by 值而导致的违反非空约束错误