Bugs item #1387369, was opened at 2005-12-22 04:03
Message generated for change (Comment added) made by jerub
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1387369&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Postgres
Group: SQLObject release (specify)
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: tables not created in correct order
Initial Comment:
When I have this code:
class ClassB(SQLObject):
...
var1=StringCol()
...
class ClassA(SQLObject):
...
var2=ForeignKey('ClassB')
...
I get an error that relation 'classb' does not exist.
So when I execute tg-admin sql create it tries to
create the ClassA table first, not checking for the
dependencies and create ClassB first.
When I created the ClassB table manually (via tg-admin
shell), it went all ok.
----------------------------------------------------------------------
Comment By: Stephen Thorne (jerub)
Date: 2005-12-22 11:51
Message:
Logged In: YES
user_id=100823
I have experenced a similar problem in the past with
SQLObject based projects. The general solution seems to be,
with databases like postgrsql, to create the foreignkeys
after all the tables have been created. This is a code
snippet that I have used in the past for creating a bunch of
tables correctly (used with SQLObject 0.6.0, so don't be
surprised if it doesn't work with the latest SQLObject):
fkeys = []
tablename = []
pgCSQL = sqlobject.ForeignKey.baseClass.postgresCreateSQL
def newfk(c):
fkeys.append((tablename[-1], pgCSQL(c).split(',')[1]))
return pgCSQL(c).split(',')[0]
sqlobject.ForeignKey.baseClass.postgresCreateSQL = newfk
import database
import views
c = database.__connection__
c.autoCommit = True
for x in database.__all__:
o = getattr(database, x)
tablename.append(o._table)
o.createTable()
for table, key in fkeys:
c.query("ALTER TABLE %s ADD %s" % (table, key))
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1387369&group_id=74338
|