{"action":"opened","issue":{"url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/347","labels_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/347/labels{/name}","comments_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/347/comments","events_url":"https://api.github.com/repos/mitsuhiko/flask-sqlalchemy/issues/347/events","html_url":"https://github.com/mitsuhiko/flask-sqlalchemy/issues/347","id":115973292,"number":347,"title":"Bind works only for same schema name","user":{"login":"whitish","id":3677259,"avatar_url":"https://avatars.githubusercontent.com/u/3677259?v=3","gravatar_id":"","url":"https://api.github.com/users/whitish","html_url":"https://github.com/whitish","followers_url":"https://api.github.com/users/whitish/followers","following_url":"https://api.github.com/users/whitish/following{/other_user}","gists_url":"https://api.github.com/users/whitish/gists{/gist_id}","starred_url":"https://api.github.com/users/whitish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitish/subscriptions","organizations_url":"https://api.github.com/users/whitish/orgs","repos_url":"https://api.github.com/users/whitish/repos","events_url":"https://api.github.com/users/whitish/events{/privacy}","received_events_url":"https://api.github.com/users/whitish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-09T21:41:18Z","updated_at":"2015-11-09T21:41:18Z","closed_at":null,"body":"I want to create my model in two different databases (e.g., in Postgres and Redshift) with different shema names. E.g., in postgres i have schema *public*, and in redshift schema called *data*.\r\n\r\nE.g., I have two engines:\r\n```python\r\nSQLALCHEMY_BINDS = {\r\n    'ranker':   app.config['SQLALCHEMY_DATABASE_URI'],\r\n    'amp_data': 'redshift+psycopg2://dbuser:pass@dbhost.redshift.amazonaws.com:5439/mydb'\r\n}\r\n```\r\n\r\nHere is a model:\r\n```python\r\nclass Campaign(Base):\r\n    __tablename__ = 'campaign'\r\n    #__bind_key__ = 'data'\r\n    campaignid = Column(Integer, primary_key=True)\r\n    campaign_name = Column(String(120))\r\n    smth = Column(BigInteger)\r\n```\r\n\r\nFirst, I tried to create declarative base and bind it explicitly (which works good but doesn't solve my problem 'cos I need to define model twice for each schema):\r\n```python\r\nengine = create_engine('redshift+psycopg2://dbuser:pass@dbhost.redshift.amazonaws.com:5439/mydb')\r\nBase = declarative_base()\r\nBase.metadata = MetaData(bind=engine, schema='data')\r\nBase.metadata.create_all(bind=engine)\r\n```\r\nBut what I expect to do with binds is to use same model and create it in different schemas on different DBs. So I can use *__bind_key__* to indicate which DB i want to use but still can't change the **schema name** for different DBs though.\r\n\r\nAppreciate for any hints."}}