On Mon, 17 Jul 2006 11:59:40 -0700, Randall Smith <[EMAIL PROTECTED]> wrote:

> The following was done with SVN trunk 1712.
>
> I have a table defined as such:
>
> schemaname='web'
> metadata = DynamicMetaData(name="web_metadata")
>
> visit_identities = Table("visit_identities", metadata,
>      Column("id", INTEGER, primary_key=True),
>      Column("visit_key", String(40), nullable=False, unique=True),
>      Column("user_id", INTEGER, ForeignKey(users.c.id), index=True),
>      schema=schemaname
> )
>
> users is a table defined in the same way.  Notice the schema =
> schemaname part.  When I map an engine to metadata and issue the command:
>
>      visit_identities.create()
>
> I get the following error:
>
> sqlalchemy.exceptions.SQLError: (ProgrammingError) relation "users" does
> not exist
>   '\nCREATE TABLE web.visit_identities (\n\tid SERIAL NOT NULL,
> \n\tvisit_key VARCHAR(40) NOT NULL, \n\tuser_id INTEGER, \n\tPRIMARY KEY
> (id), \n\t FOREIGN KEY(user_id) REFERENCES users (id)\n)\n\n' {}
>
> The create method is not taking into account the schema of users.  I
> believe that previous versions of SA did take into account the schema
> when a ForeignKey was defined with a direct reference.
>

individual table creation (ddl) doesn't take into account dependencies, it  
expects dependent tables to already be in place.

as an alternative you can use.

metadata.create_all()

which will create tables bound to the metadata iff they don't exist, which  
does take into account table fk dependencies.

cheers,

kapil


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to