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

ACV*_*ACV 5 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)
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

我正在使用SQLAlchemy 0.9.1.我的后端是在localhost上运行的MySQL.至于我可以用PDB检查告知connection,session,Base,Column,和Integer都显得正常.

Lit*_*eye 7

Integer没有参数.这是0.9版本的更改.

存在BigIntegerSmallInteger不是.

  • 请注意,它采用0.8版本的参数:[docs](http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#sqlalchemy.types.Integer). (3认同)