Menu

#59 Let admin create tables with no foreign keys first

closed-fixed
nobody
None
5
2006-03-28
2006-03-25
No

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

Discussion

  • Dennis Brakhane

    Dennis Brakhane - 2006-03-25

    Patch to manager/command.py

     
  • Oleg Broytman

    Oleg Broytman - 2006-03-27
    • status: open --> open-invalid
     
  • Oleg Broytman

    Oleg Broytman - 2006-03-27

    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?

     
  • Dennis Brakhane

    Dennis Brakhane - 2006-03-27

    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.

     
  • Oleg Broytman

    Oleg Broytman - 2006-03-28

    Logged In: YES
    user_id=4799

    Ok, then.

     
  • Oleg Broytman

    Oleg Broytman - 2006-03-28
    • status: open-invalid --> closed-fixed
     

Log in to post a comment.