SQLObject gets confused about table relations

21 views
Skip to first unread message

rjc...@gmail.com

unread,
Apr 4, 2006, 8:41:52 PM4/4/06
to TurboGears
I am using TG.9a2
It appears that SQLObject gets confused about table relations.

class List(SQLObject):
title = UnicodeCol(notNone=True)
user = ForeignKey('User')
items = MultipleJoin('Item')

class User(SQLObject):
email = StringCol(alternateID=True)
lists = MultipleJoin('List')

class Item(SQLObject):
value = UnicodeCol(notNone=True)
list = ForeignKey('List')

Causes Error:
psycopg2.ProgrammingError: relation "list" does not exist
Reordering the classes with cause whichever class is first to receive
this warning.

Per the suggestion at:
http://joe.sl4g.com/words/code/sqlobject_order.html
I added the line:
soClasses = ('List','User','Item')

The class appears to be seen but I get the error:
psycopg2.ProgrammingError: syntax error at or near "user" at character
149

Roger Demetrescu

unread,
Apr 4, 2006, 10:00:18 PM4/4/06
to turbo...@googlegroups.com
Hi...

from http://www.sqlobject.org/SQLObject.html#many-to-many-relationships
first example:


>>> class User(SQLObject):
...
... class sqlmeta:
... # user is a reserved word in some databases, so we won't
... # use that for the table name:
... table = "user_table"
...
... username = StringCol(alternateID=True, length=20)
... # We'd probably define more attributes, but we'll leave
... # that exercise to the reader...
...
... roles = RelatedJoin('Role')

So try to avoi using "user" as a fieldname/table name..

[]s
Roger

rjc...@gmail.com

unread,
Apr 4, 2006, 10:44:24 PM4/4/06
to TurboGears
User replaced by Cat causes the same error.

rjc...@gmail.com

unread,
Apr 5, 2006, 4:34:21 AM4/5/06
to TurboGears
Seems to run (with help) now but I am not comfortatble with the
process.
Replaced "User" with "Cat"
I removed the soClasses line and ran tg-admin sql create.
Error: list does not exist.
Replaced the soClasses line and ran 'admin sql create' and it seems to
work.
Delete the table and try again with the soClasses line in and get:
psycopg2.ProgrammingError: relation "cat" does not exist
Comment out soClass and get:

psycopg2.ProgrammingError: relation "list" does not exist
Uncomment soClass and run tg-admin sql create and it works.
What? It works only if forced to fail once?

Claudio Torcato

unread,
Apr 5, 2006, 6:12:24 AM4/5/06
to TurboGears
SQLObject failed when it works relations above two tables. Ex.:

Title [1 ----- *] Subttile [1 ---- *] "Undertitle"

Jorge Vargas

unread,
Apr 5, 2006, 10:41:13 AM4/5/06
to turbo...@googlegroups.com
are you doing tg-admin sql drop each time?

rjc...@gmail.com

unread,
Apr 5, 2006, 4:17:15 PM4/5/06
to TurboGears
I was droping the tables from the postgre admin program.
The tg-admin sql drop would return:
psycopg2.ProgrammingError: cannot drop table list because other objects
depend on it.

Jorge Vargas

unread,
Apr 8, 2006, 10:29:28 AM4/8/06
to turbo...@googlegroups.com
I believe you confused SQLObject very badly

please try
tg-admin sql status

tg-admin sql list

I believe you will have to sync your tables/ objects manually.


Reply all
Reply to author
Forward
0 new messages