相关疑难解决方法(0)

将对象添加到SQLAlchemy关联对象时的KeyError

我有两张桌子,tablet并且correspondent:

class Correspondent(db.Model, GlyphMixin):
    # PK column and tablename etc. come from the mixin
    name = db.Column(db.String(100), nullable=False, unique=True)
    # association proxy
    tablets = association_proxy('correspondent_tablets', 'tablet')

    def __init__(self, name, tablets=None):
        self.name = name
        if tablets:
            self.tablets = tablets


class Tablet(db.Model, GlyphMixin):
    # PK column and tablename etc. come from the mixin
    area = db.Column(db.String(100), nullable=False, unique=True)
    # association proxy
    correspondents = association_proxy('tablet_correspondents', 'correspondent')

    def __init__(self, area, correspondents=None):
        self.area = area
        if correspondents:
            self.correspondents = correspondents


class …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy

10
推荐指数
1
解决办法
5829
查看次数

标签 统计

python ×1

sqlalchemy ×1