Thread: [SQLObject] creating tables with ForeignKeys
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Jachin R. <jac...@gm...> - 2006-04-05 09:40:25
|
hi there I'm new to SQLObject and I have spent the last couple of hours struggling with ForeignKey() Here's the standard setup: class Person(SQLObject): firstName = StringCol() middleInitial = StringCol(length=1, default=None) lastName = StringCol() addresses = MultipleJoin('Address') class Address(SQLObject): person = ForeignKey("Person", alternateID=True, cascade=True) street1 = StringCol(length=64) street2 = StringCol(length=64) street3 = StringCol(length=64) city = StringCol(length=64) postCode = StringCol(length=10) Now if I do this: Address.createTable() I get one of these: psycopg2.ProgrammingError: relation "person" does not exist However if I do this: Person.createTable() Address.createTable() Everything is fine. I've been up for a while so I could be missing something obvious but I didn't see anything in the documentation that said that when I'm dealing with one-to-many relationships I have to create the "one" table before I created the "many" table. Is this the case? Or is there something else going on here that I'm not aware of? thanks -jachin |
From: Oleg B. <ph...@ma...> - 2006-04-05 10:12:47
|
On Wed, Apr 05, 2006 at 04:39:13AM -0500, Jachin Rupe wrote: > I've been up for a while so I could be missing something obvious but I > didn't see anything in the documentation that said that when I'm dealing > with one-to-many relationships I have to create the "one" table before I > created the "many" table. If you are dealing with relations in a Real DBMS like Postgres you must create a referred table before creating a referring column. It is a general rule, I don't think we need this in our docs. It has nothing with "one" or "many", though. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Jachin R. <jac...@gm...> - 2006-04-05 19:49:14
|
Oleg Broytmann wrote: > On Wed, Apr 05, 2006 at 04:39:13AM -0500, Jachin Rupe wrote: >> I've been up for a while so I could be missing something obvious but I >> didn't see anything in the documentation that said that when I'm dealing >> with one-to-many relationships I have to create the "one" table before I >> created the "many" table. > > If you are dealing with relations in a Real DBMS like Postgres you must > create a referred table before creating a referring column. It is a general > rule, I don't think we need this in our docs. > It has nothing with "one" or "many", though. Thank you for clearing that up. I never really have worked with relations in a "Real DBMS" before. I'll be sure to consult the Postgres documentation in the future. -jachin > > Oleg. |