gpt4 book ai didi

postgresql - SQLAlchemy 不为主键字段生成序列

转载 作者:行者123 更新时间:2023-11-29 13:57:29 28 4
gpt4 key购买 nike

我有以下模型:

class GeoLocation(Base):
__tablename__ = "geolocations"
id = Column(SmallInteger, primary_key=True)
name = Column(String(8), nullable=False)
coordinates = Column(String(80), nullable=False)

使用 SQLAlchemy 0.9.8 和 postgresql 9.3.6 生成正确的创建语句:

CREATE TABLE geolocations (
id SMALLSERIAL NOT NULL,
name VARCHAR(8) NOT NULL,
coordinates VARCHAR(80) NOT NULL,
PRIMARY KEY (id)
)

在另一台机器上,相同的 SQLAlchemy 版本,但在 postgresql 9.1.13 中没有,产生:

CREATE TABLE geolocations (
id SMALLINT NOT NULL,
name VARCHAR(8) NOT NULL,
coordinates VARCHAR(80) NOT NULL,
PRIMARY KEY (id)
)

有什么建议吗?

最佳答案

似乎区别在于对 smallserial 数据类型的支持。这不适用于 postgres 9.1.13: http://www.postgresql.org/docs/9.1/static/datatype-numeric.html

关于postgresql - SQLAlchemy 不为主键字段生成序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28647825/

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