On Jun 9, 2014, at 4:32 PM, AM <[email protected]> wrote:

> Hi all.
> 
> In my app I have a bootstrap method that calls:
> 
> metadata.create_all(checkfirst)
> 
> against a postgres RDS instance.
> 
> The tables already exist however the query emitted seems to be:
> 
> CREATE TABLE user_roles (
>        user_id INTEGER NOT NULL,
>        role_id INTEGER NOT NULL,
>        PRIMARY KEY (user_id, role_id),
>        FOREIGN KEY(user_id) REFERENCES "user" (id),
>        FOREIGN KEY(role_id) REFERENCES role (id)
> )
> 
> Per my understanding this query should not even be emitted or if it is there 
> should be a 'IF NOT EXISTS' somewhere in there.
> 
> I was wondering if someone could point out what I am doing wrong?

it doesn't use "IF NOT EXISTS".  it runs a query against pg_namespace.  Turn on 
echo=True on your engine and you'll see something like:

select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace 
where n.nspname=current_schema() and relname=%(name)s
{'name': u'a'}

CREATE TABLE a (
        id SERIAL NOT NULL, 
        PRIMARY KEY (id)
)

if this query isn't succeeding, perhaps you have a schema mismatch of some 
kind.  if the CREATE TABLE does succeed then the default schema is probably not 
what you expect.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to