[SQLObject] Re: [TurboGears] How to create tables with cyclic references?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2005-10-02 21:46:36
|
João Paulo Fernandes Farias wrote: > Hi! > > How do I create tables with cyclic references? > > As an example, suppose we have two classes: > > class A(SQLObject): > b = ForeignKey('B') > > class B(SQLObject): > a = ForeignKey('A') > > > /me using turbogears... > > I issue a: turbogears-admin.py sql create > > It gives me some erros because it tries to create table A but B does not > exists, so it cannot be referenced. > > My suggestion is: Create all tables and then issue all the "alter table > add constraint" as necessary. This is kind of hard. Technically you can do it like: class A(SQLObject): b = ForeignKey('B') class B(SQLObject): pass def create(): B.createTable() A.createTable() B.sqlmeta.addColumn(ForeignKey(name='a', foreignKey='A'), changeSchema=True) However, this won't work with sqlobject-admin (and thus turbogears-admin.py). |