mysql - how to join two model of two separated database python peewee -
i'm using peewee use mysql database.
import peewee db_1 = peewee.mysqldatabase('db_1', **{'user': 'root'}) db_2 = peewee.mysqldatabase('db_2', **{'user': 'root'}) class user(peewee.model): id = peewee.primarykeyfield() username = peewee.charfield() class meta: database = db_1 class tweet(peewee.model): id = peewee.primarykeyfield() tweet = peewee.charfield() user = peewee.integerfield(db_column='user_id') class meta: database = db_2
i want execute code:
m = tweet().select(tweet, user).join( user, join_type=join_inner, on=user.id == tweet.user ).where( user.id == 13 )
but raises error:
peewee.programmingerror: (1146, "table 'db_2.user' doesn't exist")
how can fix it?
i thinkbest solution problem use view
on second database. create views of users
db_2
, code work.
Comments
Post a Comment