tg-admin sql create fails when using ForeignKey

1 view
Skip to first unread message

Sean Cazzell

unread,
Oct 25, 2005, 1:01:14 AM10/25/05
to TurboGears
Hello,

I am taking a look at TurboGears and following through the getting
started guide. I have found that running "tg-admin sql create" fails
with models containing foreign keys because the create table statements
are issued in the wrong order. I am using postgresql.

Here's an example model:

class Site(SQLObject):
name = StringCol(length=25)
members = MultipleJoin('Member')

class Member(SQLObject):
site = ForeignKey('Site', unique=True)
username = StringCol(length=25)

Running "tg-admin sql sql" outputs the following:

CREATE TABLE member (
id SERIAL PRIMARY KEY,
site_id INT UNIQUE, CONSTRAINT site_id_exists FOREIGN KEY (site_id)
REFERENCES site (id) ,
username VARCHAR(25)
);

CREATE TABLE site (
id SERIAL PRIMARY KEY,
name VARCHAR(25)
);


And "tg-admin sql create" fails on the CREATE TABLE member statement as
the site table does not exist yet. Is this a known limitation, or is
there some way around this?


Kind Regards,

Sean Cazzell

william

unread,
Oct 25, 2005, 1:15:52 AM10/25/05
to TurboGears
Folllowing SQLObject people this will be fixed in version 0.8.

But with current version, several workaround exists:

Check my diary, you will see which solution I'm using, and you'll have
a link to an another solution.
http://projectsmgt.opensource4you.org/ProjectsMgt/wiki/MyDiary

Patrick Lewis

unread,
Oct 25, 2005, 9:17:56 AM10/25/05
to TurboGears
One solution is using the --class parameter and doing them one at a
time in the correct order:

tg-admin sql create --class=Site
tg-admin sql create --class=Memeber

Reply all
Reply to author
Forward
0 new messages