Hello!


I can't create table in just created schema without commit() after CreateSchema 
statement, code and traceback posted below.

Is it Ok? Or I make something wrong? 


PS. Can I call CreateSchema with ".execute_if(callable_=should_create)" ?



from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import CreateSchema

from epsilon.models import Base, SYSTEM_SCHEMA, SYSTEM_MODELS


engine = 
create_engine('postgresql+psycopg2://USER:PASSWORD@127.0.0.1:5432/epsilon', 
echo=True)
DBSession = sessionmaker(bind=engine)()
Base.metadata.bind = engine

def create_schema(name):
    s = CreateSchema(name)
    DBSession.execute(s)
    #DBSession.commit() // IF I uncomment this line, everything work fine

try:
    create_schema(SYSTEM_SCHEMA)

    DBSession.execute('SET search_path TO %s' % SYSTEM_SCHEMA)
    for m in SYSTEM_MODELS:
        m.__table__.create(checkfirst=True)
    DBSession.commit()
except:
    DBSession.rollback()
    raise




*2015-06-28 20:39:04,633 INFO sqlalchemy.engine.base.Engine select version()
2015-06-28 20:39:04,633 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,634 INFO sqlalchemy.engine.base.Engine select 
current_schema()
2015-06-28 20:39:04,635 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,636 INFO sqlalchemy.engine.base.Engine SELECT CAST('test 
plain returns' AS VARCHAR(60)) AS anon_1
2015-06-28 20:39:04,636 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,637 INFO sqlalchemy.engine.base.Engine SELECT CAST('test 
unicode returns' AS VARCHAR(60)) AS anon_1
2015-06-28 20:39:04,638 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,639 INFO sqlalchemy.engine.base.Engine show 
standard_conforming_strings
2015-06-28 20:39:04,639 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,640 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2015-06-28 20:39:04,640 INFO sqlalchemy.engine.base.Engine CREATE SCHEMA system
2015-06-28 20:39:04,640 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,641 INFO sqlalchemy.engine.base.Engine SET search_path TO 
system
2015-06-28 20:39:04,641 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,650 INFO sqlalchemy.engine.base.Engine select relname from 
pg_class c join pg_namespace n on n.oid=c.relnamespace where 
n.nspname=%(schema)s and relname=%(name)s
2015-06-28 20:39:04,650 INFO sqlalchemy.engine.base.Engine {'name': 
u'locality', 'schema': u'system'}
2015-06-28 20:39:04,654 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE system.locality (
        id SERIAL NOT NULL, 
        parent_id INTEGER, 
        name TEXT NOT NULL, 
        type INTEGER NOT NULL, 
        schema VARCHAR(63) NOT NULL, 
        PRIMARY KEY (id), 
        FOREIGN KEY(parent_id) REFERENCES system.locality (id), 
        UNIQUE (schema)
)


2015-06-28 20:39:04,654 INFO sqlalchemy.engine.base.Engine {}
2015-06-28 20:39:04,654 INFO sqlalchemy.engine.base.Engine ROLLBACK
2015-06-28 20:39:04,655 INFO sqlalchemy.engine.base.Engine ROLLBACK
Traceback (most recent call last):*

*...*

*...*

*...*

*sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) schema "system" 
does not exist*


-- 
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/d/optout.

Reply via email to