Let admin create tables with no foreign keys first
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
Suppose I have the following model:
class A(SQLObject):
foo = StringCol()
b = ForeignKey("B")
class B(SQLObject):
bar = StringCol()
If I now let sqlobject-admin create the tables for me,
the order in with these are created is not defined.
If table A is created before table B, PostgreSQL will fail:
CREATE TABLE a (
id SERIAL PRIMARY KEY,
foo TEXT,
b_id INT, CONSTRAINT b_id_exists FOREIGN KEY (b_id)
REFERENCES b (id)
)
Fails with "Relation >b< does not exist"
So, I've patched manager/command.py to create tables in
the order of classes with fewest foreign keys created
first.
This might not catch all cases, but it "works for me(TM)"
Patch is attached
Patch to manager/command.py
Logged In: YES
user_id=4799
.createTable() in the trunk has got a feature - it can delay
creating foreign keys and instead return SQL query to create
them later. So one can create all tables, collects these
delayed SQL queries and run them later, when all tables are
in place. Look in the FAQ:
http://svn.colorstudy.com/SQLObject/docs/FAQ.txt , question
"Mutually referencing tables".
I think I'd be better to use this feature instead of
unreliable "fewest foreign keys". Would you mind recreating
your patch?
Logged In: YES
user_id=26932
> I think I'd be better to use this feature instead of
> unreliable "fewest foreign keys". Would you mind
> recreating your patch?
Erm... What exactly should I recreate? It seems like
manager.py already has this functionality built-in.
I'm using TurboGears svn and didn't realize the external
reference to SQLObject's SVN was to the "0.7-bugfix" branch
and not the trunk. So I think the bug is already fixed.
Logged In: YES
user_id=4799
Ok, then.