well ... i think i was right when i said that this implementation doesn't work, and i don't know exactly why.

using abstract, declared_attr or __table_args__ via inheritance is not creating my models in another schema.

if i put it explicitly in the model, it works fine. inherited? nopes. no way. one question that can be raised is that "am i already using __table_args__ in those inherited ones?". yes, i am, but not all of them, and even so all tables are created in the public schema.

i'm using sa 0.8.3, psycopg2 and postgres 9.3.



On 12/05/2013 01:37 PM, Michael Bayer wrote:
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 <mailto: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 <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


--
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.

Reply via email to