here’s an example, works on this end:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class AltSchema(object):
    __table_args__ = {"schema": "test_schema"}

class A(AltSchema, Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)
    bs = relationship("B")

class B(AltSchema, Base):
    __tablename__ = 'b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('test_schema.a.id'))

e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
Base.metadata.create_all(e)

echo=True will tell all here...



On Dec 5, 2013, at 8:20 AM, Richard Gerd Kuesters <rich...@humantech.com.br> 
wrote:

> hi all!
> 
> another question: i have a postgres database, and i would like to work with 
> schemas for module models. so far so good, but i didn't find much information 
> besides it is available in sa docs.
> 
> so, i came into this: 
> http://stackoverflow.com/questions/9298296/sqlalchemy-support-of-postgres-schemas
> 
> but, i would like to declare it at the model level, not the metadata level. 
> is it possible?
> 
> i tried using __table_args__ = {'schema': 'foo'} in __abstract__, with and 
> without declared_attr decorator and also without __abstract__, neither worked 
> and all tables were created on public schema.
> 
> any tips? :)
> 
> i'm asking this because i have a LOT of tables, and declare __table_args__ in 
> all of them just because the schema seems kinda weird, since we can mixin 
> almost everything in sa.
> 
> 
> thanks in advance!
> richard.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to