postgreSQL 自增需要使用序列
1.使用SERIAL
CREATE TABLE users ( id SERIAL primary key,name character varying,password character varying )
自动创建名为users_id_seq的序列,且MAXVALUE=9223372036854775807
其余值为1
2.先创建序列,然后设置字段的自增
CREATE SEQUENCE users_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
alter table users alter column id set default nextval(‘users_id_seq‘); ?
我是采用第二种方法成功的。