Use separate declarative base classes for different databases with the same name to prevent SQLAlchemy metadata sharing. You will need to create two instances of flask_sqlalchemy.SQLAlchemy() :
app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/database1.db' app.config['SQLALCHEMY_BINDS'] = {'remote': 'sqlite:////tmp/database1.db'} db1 = SQLAlchemy(app) class Lcn(db1.Model): __tablename__ = 'lcn' db2 = SQLAlchemy(app) class LcnRemote(db2.Model): __bind_key__ = 'remote' __tablename__ = 'lcn'
This is a limitation of Flask-SQLAlchemy, it should really allow you to create declarative databases for each binding. The way the SQLAlchemy() class is currently being developed is limiting it to only one such base; it proxies various SQLAlchemy metadata calls through the db.Model class, which it generates from the very beginning. By creating two instances of flask_sqlalchemy.SQLAlchemy() , you will get around this problem.
Martijn pieters
source share