I have an extremely complex model and was running into this a lot, so I
might have a solution for you.  I'm using the trunk version of
SQLObject, which has support for the applyConstraints argument in
createTable.  First, you'll have to change a line in
site-packages/TurboGears-1.0b1/EGG-INFO/requires.txt to allow you to
use the trunk version of SQLObject:

    SQLObject==bugfix,>=0.7.1dev-r1860

Then, you need to *get* the development version using

    easy_install -U SQLObject==dev

You might need to move the old version away (just find and rename
anything except the most recent sqlobject in site-packages, and make
sure the new version is listed in site-packages/easy_install.pth.)

Once you've done all this, you should be able to use something like
this to create your model:

-- begin script --

from sqlobject import classregistry, SQLObject
from sqlobject.inheritance import InheritableSQLObject

turbogears.update_config(configfile='dev.cfg',
                         modulename='xf.config')

import xf.model
from xf.model import hub

# Find all "interesting" tables
tables = [ t for t in classregistry.registry(None).allClasses()
           if t is not SQLObject
           if t is not InheritableSQLObject
           if t.__module__ != 'turbogears.identity.soprovider'
           if issubclass(t, SQLObject) ]

# Drop all tables in the registry
hub.begin()
for t in tables:
    if t._connection.tableExists(t.sqlmeta.table):
        print 'Drop %s: %s' % (t.sqlmeta.table, t)
        t.dropTable(cascade=True, dropJoinTables=False)
hub.commit()

# Re-create all tables in the registry
hub.begin()
constraints = []
for t in tables:
    print 'Create %s' % t.sqlmeta.table
    t_const = t.createTable(applyConstraints=False)
    constraints += t_const
for c in constraints:
    hub.getConnection().query(c)
hub.commit()

-- end script --

Something very similar to this has been working for me for several
months now.  Hope it helps someone.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to