私はクロスデータベースをやろうとしているフラスコSQLAlchemyの中で参加する:これによりクロスデータベースはフラスコSQLAlchemyのに参加
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = '...Master...'
app.config['SQLALCHEMY_BINDS'] = { 'Billing': '...Billing...' }
db = SQLAlchemy(app)
class Account(db.Model):
__tablename__ = 'Accounts'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(255))
class Setting(db.Model):
__tablename__ = 'Settings'
AccountId = db.Column(db.Integer, db.ForeignKey(Account.id), primary_key=True)
Enabled = db.Column(db.Boolean)
class BillingAccount(db.Model):
__tablename__ = 'Account'
__bind_key__ = 'Billing'
id = db.Column(db.Integer, primary_key=True)
AccountId = db.Column(db.Integer, db.ForeignKey(Account.id))
currency = db.Column(db.Integer)
class AccountSetting(db.Model):
__table__ = db.join(Account, AccountSetting)
id = db.column_property(Account.id, AccountSetting.AccountId)
username = Account.username
enabled = Setting.Enabled
class AccountSettingBilling(db.Model):
__table__ = db.join(Account, AccountSetting).join(BillingAccount)
id = db.column_property(Account.id, AccountSetting.AccountId, BillingAccount.AccountId)
username = Account.username
enabled = Setting.Enabled
currency = BillingAccount.currency
私は成功しAccountSetting.query.allを(照会することができる)が、AccountSettingBillingありません.query.all()は、エラー208(「オブジェクトが存在しません」のMSSQL)で失敗します。
生成されたSQLを調べると、Accounting.AccountId = Accounts.idでJOINを実行していることがわかります。 Billing.Account.AccountId = Accounts.id。
Cross database join in sqlalchemyとhttp://pythonhosted.org/Flask-SQLAlchemy/binds.htmlの後には、正しく処理したように見えます。何がありますか?