I'm running into the following error while trying to implement many to many relation:
Was unable to import app Error: Neither 'Column' object nor 'Comparator' object has an attribute 'schema'
Here is my code:
association_table = Table('association',
Column('geo_idx', Integer, ForeignKey('geo.idx')),
Column('container_idx', Integer, ForeignKey('container.idx'))
)
class Geo(Model):
idx = Column(Integer, unique=True, primary_key=True)
name = Column(String(64), unique=True, primary_key=False)
containers = relationship("Container",
secondary=association_table, lazy = "subquery",
backref=backref('geos', lazy=True))
def __repr__(self):
return self.name
class Container(Model):
idx = Column(Integer, unique=True, primary_key=True)
name = Column(String(64), unique=True, primary_key=False)
def __repr__(self):
return self.name
I did a little bit of googling and most of the people with this error where getting it because of not capitalizing Column, however this is not the case in this instance. Any pointers would be appreciated.
Managed to get it to work by passing Model.metadata
to the association table creation function.
association_table = Table('association', Model.metadata,
Column('geo_idx', Integer, ForeignKey('geo.idx')),
Column('container_idx', Integer, ForeignKey('container.idx'))
)