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

标签 postgresql sqlalchemy

我有以下模型:

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/

相关文章:

javascript - 在 findAll 中续写计数关联

python - flask "get_or_404"类似功能但具有另一个状态代码

python - 如何为 SQLAlchemy 引擎打开一个连接?

python - 使用 Flask、SQLAlchemy 和 WTForms 更新多对多关系?

python - sqlalchemy中的分组和计数功能

python - 在 sqlalchemy 查询中包含非列值

c++ - 如何使用 SOCI 从数据库中获取整行?

postgresql - postgres 按值偏移而不是数字

postgresql - REVOKE/GRANT ALL ON FUNCTION 更改了哪些表和列

PostgreSQL 9.3 : Setting parameters values default to null