flask多对多关系报错,sqlalchemy.exc.NoForeignKeysError
book_author = db.Table("bookrelathons", db.Column("id", db.Integer, db.ForeignKey("author.id")), db.Column("id", db.Integer, db.ForeignKey("books.id")))
class Books(db.Model):
__tablename__="books"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
author = db.relationship("Author", backref="book", secondary=book_author)
class Author(db.Model):
__tablename__="author"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
诸位大神,请帮我看看这段代码为什么会报错,错误是sqlalchemy.exc.NoForeignKeysError
NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Books.author - there are no foreign keys linking these tables via secondary table 'bookrelathons'. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify 'primaryjoin' and 'secondaryjoin' expressions.