jj5*_*347 5 python mysql sqlalchemy alembic
我正在使用Alembic和SQLAlchemy进行项目,但是在测试中无法在数据库中创建简单条目。我收到以下错误:
sqlalchemy.exc.ArgumentError: Mapper Mapper|Sale|sales_cache could not assemble any primary key columns for mapped table 'sales_cache'
Run Code Online (Sandbox Code Playgroud)
我已经在下面的两个地方都建立了主键(account_id),你知道为什么SQLAlchemy无法识别该主键或如何解决它吗?我读过的其他答案都处理了多个主键/无主键的异常情况,并已相应解决,但这是一个失败的漂亮模型。
我已经阅读了其他答案,其中大多数涉及声明式系统:
class Sale(Base):
__tablename__ = 'sales_cache'
Run Code Online (Sandbox Code Playgroud)
但是我必须使用经典的制图系统。这分别是我的映射类和架构:
class Sale(object):
def __init__(self, notification):
self._sale_id = self._notification.object_id
self._account_id = self._notification.account_id
### schema.py file ###
from sqlalchemy.schema import MetaData, Table, Column
from sqlalchemy.types import (Unicode, Integer)
from database import metadata
metadata = MetaData()
sales_cache = Table('sales_cache', metadata,
Column('account_id', Integer, primary_key=True, autoincrement=False),
Column('sale_id', Integer, nullable=False)
)
Run Code Online (Sandbox Code Playgroud)
这是我的Alembic修订中的相关内容:
sa.Column('account_id', sa.Integer(), primary_key=True, autoincrement=False),
Run Code Online (Sandbox Code Playgroud)
我以为它可能会失败,因为我正在设置self._sale_id和self._account_id而不是self.sale_id和self.account_id(没有下划线),但是当我尝试这种方式时也没有任何改变。
提前致谢