pdu*_*sen 5 python postgresql sqlalchemy biginteger
如果格式不正确,我谨此致歉;对我来说已经很晚了。
基本上,我将Python与SQLAlchemy结合使用。我正在尝试使用Object Relational Mapper声明式样式将类映射到PostgreSQL DB表。
根据SQLAlchemy关于数据类型的文档,我应该能够使用该类型BigInteger
来表示数据库中潜在的大整数,尤其是因为我知道PostgreSQL支持BIGINT数据类型。
因此,我尝试像这样声明我的班级:
import sqlalchemy
from sqlalchemy import Column, BigInteger, Text, Sequence, Boolean
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Account(Base):
__tablename__ = 'accounts'
__metadata__ = Base.metadata
id = Column(BigInteger, Sequence('id_seq'), unique=True, nullable=False)
email = Column(Text(32), unique=True, nullable=False)
def __init__(self, email):
self.email = email
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用此文件时,会遇到以下问题:
Traceback (most recent call last):
File "sqltest02.py", line 9, in <module>
from account import Account
File "/home/pdusen/prog/account.py", line 2, in <module>
from sqlalchemy import Column, BigInteger, Text, Sequence, Boolean
ImportError: cannot import name BigInteger
Run Code Online (Sandbox Code Playgroud)
因此,根据SQLAlchemy的文档,该BigInteger
类型存在,但根据python则不存在。这里有什么我想念的吗?
在此先感谢您提供所有答案。
至少从SQL Alchemy 0.6起已支持此功能。如评论中所述,实际问题是版本太旧。
归档时间: |
|
查看次数: |
7855 次 |
最近记录: |