使用Integer的SQLAlchemy中出错:“object()不带参数”

时间:2014-01-16 03:36:52

标签: python sqlalchemy

我突然开始在我的Python SQLAlchemy应用程序中看到一个错误,我无法弄清楚导致它的原因。我的代码如下所示:

from sqlalchemy import create_engine
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base

def loadConnection(connection_string, echo=False):
    engine = create_engine(connection_string, echo=echo)
    Base = declarative_base(engine)
    Session = sessionmaker(bind=engine)
    session = Session()
    return session, Base

connection = yaml.load('connection.yaml')
session, Base = loadConnection(connection['connection'], connection['echo'])

class Foo(Base):
    __tablename__ = 'foo'
    id = Column(Integer(11), primary_key=True)

当我运行此脚本时,我收到以下错误:

Traceback (most recent call last):
  File "ephem/database_interface.py", line 52, in <module>
    class Foo(Base):
  File "ephem/database_interface.py", line 54, in Foo
    id = Column(Integer(11), primary_key=True)
TypeError: object() takes no parameters

我正在使用SQLAlchemy 0.9.1。我的后端是在localhost上运行的MySQL。据我所知,通过检查pdb connectionsessionBaseColumnInteger看起来都很正常。

1 个答案:

答案 0 :(得分:7)

Integer不带参数。这是版本0.9的更改。

而是存在BigIntegerSmallInteger