2

I'm using Flask-SQLAlchemy connect to multiple databases.

class Car(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    brand = db.Column(db.String(80), unique=True)

class Dog(db.Model):
    __bind_key__ = 'database_2'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)

and use command to init migrations

flask db init --multidb

then I got two databases,'default' and 'database_2'. When I use command

flask db migrate

to migrate, only default db schemas been generated to migrate scripts.

And then, when I use command

flask db upgrade

'default' and 'database_2' both got car table. Dog table didnt in the migration script.

I need car table in default db and dog table in database_2.

How can i migrate multi databases with different tables?

Need help,thank you.

  • 1
    I can't really tell you what's wrong with the little bit of code you showed, but the flask-migrate repo has a complete and working example with multiple databases that you can use as a base to debug the problem: https://github.com/miguelgrinberg/Flask-Migrate/blob/master/tests/app_multidb.py – Miguel Grinberg Jan 08 '20 at 07:40
  • 1
    Sorry for the little bit of code. I figure it out though this link https://github.com/miguelgrinberg/Flask-Migrate/issues/220 .It turns out, my second database "database_2", didn't import when the migrate command runs.Thanks though. – theNebuchadnezzar Jan 09 '20 at 07:00

0 Answers0