I am trying to bind another database (within the same server) to my Flask app. I declared the bind key on the table and used SQLALCHEMY_BINDS in my config but I am still getting the error that the table does not exist in the wrong database. Here is my code:
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://user_name:password@server/serology'
SQLALCHEMY_BINDS = {'ccr': 'mysql+pymysql://user_name:password@server/ccr'}
app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
class sample(db.Model):
__bind_key__ = 'ccr'
__tablename__ = "sample"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False)
I am getting the error of:
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1146, "Table 'serology.sample' doesn't exist")
I can't see why this is not looking for the table in the database that I bound and declared the bind key for. Any help is appreciated!