you have cross referencing tables; the second table's db.project foreign key will work because the first table is already defined when Python scans the second table definition; changing the order will just reverse your problem.
If you use the "reference ..." form, you will have no problem, and it is specifically for this situation. As a stylistic matter, I would suggest using this form in both table definitions so that you have a hint that this is a cross reference (that is that the references table also references the one containing the "reference ..." form). Regards, - Yarko On Wed, Sep 2, 2009 at 10:30 AM, greenpoise <[email protected]> wrote: > > Changing the order wont do it either? > > Thanks > > d > > > > On Sep 2, 11:28 am, mdipierro <[email protected]> wrote: > > In your first example the project table is referning a table that does > > not yet exist. You can do it but you must replace > > > > SQLField("id_project_location",db.project_location)) > > > > with > > > > SQLField("id_project_location","reference project_location")) > > > > On Sep 2, 9:43 am, greenpoise <[email protected]> wrote: > > > > > I have two samples here, one works, the other does not. They are > > > pretty similar: > > > > > Example#1 > > > > > DOES NOT WORK: > > > > > db.define_table("project", > > > SQLField("project_number", "text", notnull=True, default=None), > > > SQLField("project_name", "text", notnull=True, default=None), > > > SQLField("project_description", "text", notnull=True, > > > default=None), > > > SQLField("project_status", "integer", notnull=True, > > > default=None), > > > SQLField("contact", "integer", notnull=True, default=None) > > > SQLField("id_project_location",db.project_location)) > > > > > """ > > > Table definition > > > """ > > > db.define_table("project_location", > > > SQLField("address_1", "text", notnull=True, default=None), > > > SQLField("address_2", "text", notnull=True, default=None), > > > SQLField("address_3", "text", notnull=True, default=None), > > > SQLField("municipality", "integer", notnull=True, default=None), > > > SQLField("country", "text", notnull=True, default=None), > > > SQLField("zip_code", "text", notnull=True, default=None), > > > SQLField("id_project", db.project)) > > > > > Example#2 > > > DOES WORK: > > > > > db.define_table("project", > > > SQLField("project_number", "text", notnull=True, default=None), > > > SQLField("project_name", "text", notnull=True, default=None), > > > SQLField("project_description", "text", notnull=True, > > > default=None), > > > SQLField("project_status", "integer", notnull=True, > > > default=None), > > > SQLField("contact", "integer", notnull=True, default=None)) > > > > > """ > > > Table definition > > > """ > > > db.define_table("project_location", > > > SQLField("address_1", "text", notnull=True, default=None), > > > SQLField("address_2", "text", notnull=True, default=None), > > > SQLField("address_3", "text", notnull=True, default=None), > > > SQLField("municipality", "integer", notnull=True, default=None), > > > SQLField("country", "text", notnull=True, default=None), > > > SQLField("zip_code", "text", notnull=True, default=None), > > > SQLField("id_project", db.project)) > > > > > If I do follow example#2, I would be creating a One-Many relationship, > > > more locations per project which I do not want. Thanks > > > > > dan > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

