使用flask-sqlalchemy,我想创建一些类来继承声明性类并添加__bind_key__
. 这样我就可以创建一些表并继承这些绑定的类。
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Model1(db.Model):
__bind_key__ = 'db2'
class Table1(Model1):
__tablename__ = 'table1'
name = db.Column(db.String(100))
但是我遇到了一些麻烦:
sqlalchemy.exc.InvalidRequestError: Class <class '__main__.Model1'>
does not have a __table__ or __tablename__ specified
and does not inherit from an existing table-mapped class.
我该如何解决?