postgresql 数据库遇到的坑,relation "XXX_id_seq" does not exist
relation “XXX_id_seq” does not exist
网上的解决方法
-
第一种解释
用psotgresql练手的时候打算 从生产数据库到开发数据库 ,转存sql脚本。
运行sql脚本的时候数据和结构都刷不过来,于是检查sql脚本和报错,一直报relation “performance_id_seq” does not exist ,查阅文档得知:
在postgresql表中建立了自增字段,id定义为Serial 类型,当执行完成建表语句后,其字段便成:
“id” int4 NOT NULL DEFAULT nextval(‘performance_id_seq’::regclass)
这种形式
但是导出sql脚本时候直接定义成这种形式,postgresql不能识别,想必是postgresql的一个小bug吧,因此自增的id,在建表的时候应该定义为: “id” serial -
第二种解释
-
-
他们好像说的是一回事啊,怎么改 serial 呀,我是新手不知道啊
我的解决方法
- 新建查询,执行
CREATE SEQUENCE IF NOT EXISTS XXXX_id_seq;
- 执行sql文件
- 完成了