问题解决:数据库自增id到最大报错
pgsql数据库id自增到长度问题: django.db.utils.DataError: nextval: reached maximum value of sequence "ip_prefix_info_id_seq" (32767)
·
pgsql数据库id自增到长度问题: django.db.utils.DataError: nextval: reached maximum value of sequence "ip_prefix_info_id_seq" (32767)
schema_name: ip_management_app
table_name: ip_prefix_info
# 先把自增id改到serial8,范围改大
# 创建新的
CREATE SEQUENCE ip_management_app.ip_prefix_info_bigserial_seq;
SELECT setval('ip_management_app.ip_prefix_info_bigserial_seq', COALESCE(MAX(id), 0)) FROM ip_management_app.ip_prefix_info;
ALTER TABLE ip_management_app.ip_prefix_info ALTER COLUMN id TYPE bigint;
ALTER TABLE ip_management_app.ip_prefix_info ALTER COLUMN id SET DEFAULT nextval('ip_management_app.ip_prefix_info_bigserial_seq'::regclass);
# 删除旧的
DROP SEQUENCE ip_management_app.ip_prefix_info_id_seq;
# 新的改为旧的名称
ALTER SEQUENCE ip_management_app.ip_prefix_info_bigserial_seq RENAME TO ip_prefix_info_id_seq;
更多推荐
已为社区贡献3条内容
所有评论(0)