gpt4 book ai didi

mysql - MySql数据库转换为Postgres数据库时没有自动增量

转载 作者:行者123 更新时间:2023-11-29 22:30:03 25 4
gpt4 key购买 nike

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

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

关于mysql - MySql数据库转换为Postgres数据库时没有自动增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29889217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com