MySql 数据库转换为 Postgres 数据库时没有自动递增

No auto Increment when MySql Database converted to Postgres database

Mysql中,IDAuto Increment,但是当转换为Postgres时,就没有Auto Increment

Mysql 数据库

CREATE TABLE IF NOT EXISTS `cities` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `state_id` bigint(20) NOT NULL,
  `district_id` bigint(20) NOT NULL,
   `name` varchar(255) NOT NULL,
  `description` varchar(1000) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `modified_by` int(11) DEFAULT NULL,
  `is_active` char(1) NOT NULL DEFAULT 'Y',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `state_id` (`state_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;

转换为 postgres 数据库后

CREATE TABLE cities (
    "id" bigint NOT NULL,
    state_id bigint NOT NULL,
    district_id bigint NOT NULL,
    "name" varchar(255) NOT NULL,
    description varchar(1000),
    created_by int NOT NULL,
    modified_by int,
    is_active char(1) NOT NULL,
    created timestamp,
    modified timestamp,
    PRIMARY KEY ("id")
);

INSERT INTO cities(state_id, district_id, city_type, name, description,  
     created_by, modified_by, is_active, created, modified) 
VALUES 
    (1, 1, '', 'Ramtek', null, 1, null, 'Y',
     '2015-04-16 10:44:11', '2015-04-16 10:44:11');

在这种情况下,您可以使用 bigserial。它在 postgres 中提供了一个自动增量功能:

CREATE TABLE cities (
   "id" bigserial PRIMARY KEY,

默认提供Not Null约束

文档:http://www.postgresql.org/docs/current/static/datatype.html#DATATYPE-SERIAL