Turbogears 2 / SQLAlchemy - tables with a foreign key

22 views
Skip to first unread message

Artem Marchenko

unread,
Jan 11, 2009, 7:53:57 AM1/11/09
to TurboGears
Hi

I am trying to create two tables linked by a simple one-to-many
relationship. Following the David's advice (
http://groups.google.com/group/turbogears/browse_thread/thread/ea7da1151d9f881d
) I was able to make SQLAlchemy link two classes, but I can't make it
actually create tables with the ForeignKeys. Whenever I am trying to
do it (already on the metadata.drop_all step) I get
----------------
hema.py", line 845, in column
"foreign key" % tname)
sqlalchemy.exc.NoReferencedTableError: Could not find table
'worpairtopics' with
which to generate a foreign key
----------------

So it fails to create a foreign key to the non-existing table. I don't
mind creating tables one by one, but can't get how to do that
correctly. Naive commenting the second class out during the first
create_all call didn't help - I still get the same error even if the
referenced table already exists (I think). I guess I am missing
something very basic. Please help.

Here is my very simple model. It is just a set of WordPairs belonging
to WordPairTopic's - http://paste.turbogears.org/paste/25578

And here is my DB initialization script that fails (modeled closely
after Wiki20 tutorial) - http://paste.turbogears.org/paste/25579

Please, help. It should be something very simple for anybody who has
ever created linked classes in TG2 - SQLAlchemy.

Best regards,
Artem.

Diez B. Roggisch

unread,
Jan 11, 2009, 12:00:47 PM1/11/09
to turbo...@googlegroups.com
Artem Marchenko schrieb:

> Hi
>
> I am trying to create two tables linked by a simple one-to-many
> relationship. Following the David's advice (
> http://groups.google.com/group/turbogears/browse_thread/thread/ea7da1151d9f881d
> ) I was able to make SQLAlchemy link two classes, but I can't make it
> actually create tables with the ForeignKeys. Whenever I am trying to
> do it (already on the metadata.drop_all step) I get
> ----------------
> hema.py", line 845, in column
> "foreign key" % tname)
> sqlalchemy.exc.NoReferencedTableError: Could not find table
> 'worpairtopics' with
> which to generate a foreign key
> ----------------

Naming the table correctly helps tremendously when declaring foreign
keys... :)

Diez

Artem Marchenko

unread,
Jan 13, 2009, 7:22:07 AM1/13/09
to TurboGears
I knew it was something simple! :)
Thank you, Diez!

After fixing the typo in the table name, everything works.

Best regards,
Artem.

On Jan 11, 7:00 pm, "Diez B. Roggisch" <de...@web.de> wrote:
> Artem Marchenko schrieb:
>
> > Hi
>
> > I am trying to create two tables linked by a simple one-to-many
> > relationship. Following the David's advice (
> >http://groups.google.com/group/turbogears/browse_thread/thread/ea7da1...
Reply all
Reply to author
Forward
0 new messages