【发布时间】:2011-07-18 15:02:01
【问题描述】:
如果格式不正确,我提前道歉;对我来说已经很晚了。
基本上,我将 Python 与 SQLAlchemy 结合使用。我正在尝试使用Object Relational Mapper, declarative style 将一个类映射到 PostgreSQL 数据库表。
根据SQLAlchemy's documentation on data types,我应该能够使用BigInteger 类型来表示数据库中潜在的大整数,特别是因为我知道PostgreSQL supports the BIGINT data type。
所以,我尝试像这样声明我的类:
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
但是,当我尝试使用这个文件时,我收到了以下信息:
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
因此,根据 SQLAlchemy 的文档,BigInteger 类型存在,但根据 python,它不存在。这里有什么我想念的吗?
提前感谢所有答案。
【问题讨论】:
-
很可能您使用的是旧版本的 SQLAlchemy,它不支持
BigInteger,但阅读文档以获得较新的版本。 -
你是对的。当然,事情就是这么简单。当然,现在我遇到了一个完全不同的问题(字符串编码......呃)。感谢您的评论。
标签: python postgresql sqlalchemy biginteger