对于我的应用程序,我需要创建一个带有相同实体的点的链接。目前我是这样做的。
association_table = db.Table('main_connectedpoints', Base.metadata,
db.Column('point_id', db.Integer, db.ForeignKey('main_placepoint.id')),
db.Column('connected_point_id', db.Integer, db.ForeignKey('main_placepoint.id')))
class PlacePoint(db.Model):
__tablename__ = 'main_placepoint'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String())
lat = db.Column(db.Float())
lon = db.Column(db.Float())
address = db.Column(db.String())
organizations = db.relationship('Organization', backref='main_placepoint',
lazy='dynamic')
related_points = db.relationship("PlacePoint",
secondary=lambda: association_table)
def __init__(self, dict_):
self.name = dict_['name']
self.lat = dict_['lat']
self.lon = dict_['lon']
self.address = dict_['address']
def __repr__(self):
return "Place %r" % self.address
def as_dict(self):
return {"name": self.name, "lat": self.lat, "lon": self.lon, "address": self.address}
但是我有以下错误:NoReferencedTableError:与列关联的外键' main_connectedpoints.point_id'找不到表' main_placepoint'用于生成目标列' id'
的外键我认为这是因为PlacePoint
类没有实例化。有什么想法来解决它吗?