我有以下模型:
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/