簡體   English   中英

使用Integer的SQLAlchemy中出錯:“object()不帶參數”

[英]Error in SQLAlchemy with Integer: “object() takes no parameters”

我突然開始在我的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看起來都很正常。

Integer不帶參數。 這是0.9版本的更改。

而是存在BigIntegerSmallInteger

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM