NameError: name 'ForeignKey' is not defined

1,658 views
Skip to first unread message

hoboro

unread,
Feb 12, 2008, 3:29:06 PM2/12/08
to TurboGears
I seem to be getting the ForeignKey not defined. What version of
SQLObject needs to be installed?

rom turbogears.database import PackageHub
# import some basic SQLObject classes for declaring the data model
# (see http://www.sqlobject.org/SQLObject.html#declaring-the-class)
from sqlobject import SQLObject, SQLObjectNotFound, RelatedJoin
# import some datatypes for table columns from SQLObject
# (see http://www.sqlobject.org/SQLObject.html#column-types for more)


model.py

rom sqlobject import StringCol, UnicodeCol, IntCol, DateTimeCol

__connection__ = hub = PackageHub('vsjservice')


class Customer(SQLObject):
firstName = StringCol(length=50)
lastName = StringCol(length=50)
phone = StringCol(length=20)
company = StringCol(length=80)

class Workorder(SQLObject):
item = StringCol(length=80)
problem = StringCol(length=255)
repairnote = StringCol(length=255)
customer = ForeignKey("Customer")

# your data model




ERROR:

12/01/2007 08:04 PM 765 pyparsing-wininst.log
01/24/2008 03:17 PM 3,794 pysqlite-wininst.log
01/24/2008 03:17 PM <DIR> pysqlite2-doc
04/18/2007 08:51 AM 24,064 python.exe
04/18/2007 08:51 AM 24,576 pythonw.exe
04/05/2007 09:09 AM 56,975 README.txt
01/27/2008 10:38 PM 61,440 RemoveCherryPy.exe
01/23/2008 11:19 AM 61,440 Removemlabwrap.exe
08/03/2007 12:56 PM 61,440 RemoveMySQL-python.exe
01/24/2008 11:07 AM 61,440 Removenumpy.exe
12/01/2007 08:04 PM 61,440 Removepyparsing.exe
01/24/2008 03:17 PM 61,440 Removepysqlite.exe
12/05/2007 05:54 PM 2,104 reset root password mysql.txt
11/30/2007 02:48 PM <DIR> Sample Programs
01/31/2008 01:51 PM <DIR> Scripts
01/31/2008 10:30 AM 1,975 simplebot.py
11/01/2007 01:56 PM <DIR> SpiderCache
01/28/2008 10:37 AM <DIR> SQLAlchemy-0.4.2p3
01/31/2008 12:00 PM <DIR> SQLObject-0.8.6
01/31/2008 01:51 PM <DIR> Supybot-0.83.2
12/01/2007 08:03 PM <DIR> tcl
01/22/2008 02:08 PM <DIR> testpackage
01/27/2008 10:55 PM 16,068 tgsetup.py
12/01/2007 08:03 PM <DIR> Tools
01/31/2008 11:31 AM 75,651 unins000.dat
01/31/2008 11:31 AM 673,546 unins000.exe
02/12/2008 03:07 PM <DIR> vsjservice
04/18/2007 08:51 AM 4,608 w9xpopen.exe
12/06/2007 11:55 AM 7,384 webcrawlermysql_ver1.py
01/15/2008 03:39 PM 5,394 webcrawlermysql_ver1.pyc
01/15/2008 07:20 AM 7,292 webcrawler_test.py
12/01/2007 05:23 PM 6,471 webcrawler_ver1.py
12/04/2007 12:43 AM 0 webcrawl_status.txt
01/17/2008 11:52 AM 22,016 wordlist.xls
40 File(s) 6,021,551 bytes
30 Dir(s) 61,987,627,008 bytes free

C:\Python25>dir
Volume in drive C has no label.
Volume Serial Number is E4E5-DEA3

Directory of C:\Python25

02/12/2008 03:07 PM <DIR> .
02/12/2008 03:07 PM <DIR> ..
08/12/2007 11:30 AM 148,241 all_ham.dat
01/27/2008 10:38 PM <DIR> cherrypy
01/27/2008 10:45 PM <DIR> CherryPy-3.0.3
01/27/2008 10:38 PM 16,564 CherryPy-wininst.log
11/01/2007 01:06 PM <DIR> chilkatPython
02/05/2008 04:09 PM 1,908,110 chilkatPython.rar
08/21/2007 04:36 PM 146,675 choose_phishing.dat
01/16/2008 05:45 PM <DIR> CraigsList_Deceptive
11/29/2007 12:45 PM 950 DataAccess.py
11/30/2007 09:14 PM 1,386 DataAccess.pyc
01/24/2008 12:44 PM <DIR> Deceptive
11/19/2007 06:41 PM <DIR> diveintopython-examples-5.4
01/25/2008 10:43 AM <DIR> Django-0.96.1
12/01/2007 08:02 PM <DIR> DLLs
01/16/2008 07:13 PM <DIR> Doc
01/28/2008 03:34 PM <DIR> docutils-0.4
01/31/2008 12:14 PM 1,756,695 docutils-0.4.rar
01/30/2008 12:54 PM <DIR> extensions
11/01/2007 07:28 PM <DIR> FacebookClient
12/04/2007 08:54 AM 1,260 filestoprocess.sql
01/25/2008 04:39 PM 259 file_name
11/01/2007 01:32 PM <DIR> GUIExamples
12/01/2007 08:02 PM <DIR> include
02/11/2008 11:05 AM <DIR> Lib
01/24/2008 11:09 AM <DIR> libs
01/15/2008 06:46 AM 47 ListOfURLs.txt
01/23/2008 11:19 AM 1,262 mlabwrap-wininst.log
07/18/2007 02:33 PM 348,160 msvcr71.dll
10/22/2007 01:17 PM 129 MySQL Basics.txt
08/03/2007 12:56 PM 4,290 MySQL-python-wininst.log
04/18/2007 08:44 AM 106,394 NEWS.txt
11/06/2007 02:25 PM <DIR> nltk-0.9
01/24/2008 11:07 AM 74,034 numpy-wininst.log
10/23/2007 11:23 AM 205,772 pymssql-0.8.0.win32-py2.5.exe
12/01/2007 08:04 PM 765 pyparsing-wininst.log
01/24/2008 03:17 PM 3,794 pysqlite-wininst.log
01/24/2008 03:17 PM <DIR> pysqlite2-doc
04/18/2007 08:51 AM 24,064 python.exe
04/18/2007 08:51 AM 24,576 pythonw.exe
04/05/2007 09:09 AM 56,975 README.txt
01/27/2008 10:38 PM 61,440 RemoveCherryPy.exe
01/23/2008 11:19 AM 61,440 Removemlabwrap.exe
08/03/2007 12:56 PM 61,440 RemoveMySQL-python.exe
01/24/2008 11:07 AM 61,440 Removenumpy.exe
12/01/2007 08:04 PM 61,440 Removepyparsing.exe
01/24/2008 03:17 PM 61,440 Removepysqlite.exe
12/05/2007 05:54 PM 2,104 reset root password mysql.txt
11/30/2007 02:48 PM <DIR> Sample Programs
01/31/2008 01:51 PM <DIR> Scripts
01/31/2008 10:30 AM 1,975 simplebot.py
11/01/2007 01:56 PM <DIR> SpiderCache
01/28/2008 10:37 AM <DIR> SQLAlchemy-0.4.2p3
01/31/2008 12:00 PM <DIR> SQLObject-0.8.6
01/31/2008 01:51 PM <DIR> Supybot-0.83.2
12/01/2007 08:03 PM <DIR> tcl
01/22/2008 02:08 PM <DIR> testpackage
01/27/2008 10:55 PM 16,068 tgsetup.py
12/01/2007 08:03 PM <DIR> Tools
01/31/2008 11:31 AM 75,651 unins000.dat
01/31/2008 11:31 AM 673,546 unins000.exe
02/12/2008 03:09 PM <DIR> vsjservice
04/18/2007 08:51 AM 4,608 w9xpopen.exe
12/06/2007 11:55 AM 7,384 webcrawlermysql_ver1.py
01/15/2008 03:39 PM 5,394 webcrawlermysql_ver1.pyc
01/15/2008 07:20 AM 7,292 webcrawler_test.py
12/01/2007 05:23 PM 6,471 webcrawler_ver1.py
12/04/2007 12:43 AM 0 webcrawl_status.txt
01/17/2008 11:52 AM 22,016 wordlist.xls
40 File(s) 6,021,551 bytes
30 Dir(s) 61,987,622,912 bytes free

C:\Python25>cd vsjservice

C:\Python25\vsjservice>dir
Volume in drive C has no label.
Volume Serial Number is E4E5-DEA3

Directory of C:\Python25\vsjservice

02/12/2008 03:09 PM <DIR> .
02/12/2008 03:09 PM <DIR> ..
02/12/2008 03:09 PM 1,910 dev.cfg
02/12/2008 03:07 PM 130 README.txt
02/12/2008 03:07 PM 2,605 sample-prod.cfg
02/12/2008 03:07 PM 2,476 setup.py
02/12/2008 03:07 PM 1,251 setup.pyc
02/12/2008 03:07 PM 488 start-vsjservice.py
02/12/2008 03:07 PM 529 test.cfg
02/12/2008 03:07 PM <DIR> vsjservice
02/12/2008 03:07 PM <DIR> vsjservice.egg-info
7 File(s) 9,389 bytes
4 Dir(s) 61,987,622,912 bytes free

C:\Python25\vsjservice>tg-admin sql create
Traceback (most recent call last):
File "C:\Python25\Scripts\tg-admin-script.py", line 8, in <module>
load_entry_point('turbogears==1.0.4.2', 'console_scripts', 'tg-
admin')()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 370, in main
command = command(turbogears.__version__)
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 85, in __init__
self.find_config()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 48, in find_config
load_project_config(self.config)
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\ut
il.py", line 97, in load_project_config
modulename = package + ".config")
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
nfig.py", line 206, in update_config
configdict = config_obj(configfile, modulename).dict()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
nfig.py", line 192, in config_obj
configdata2 = ConfigObj(configfile, unrepr=True)
File "C:\Python25\lib\site-packages\configobj-4.4.0-py2.5.egg
\configobj.py", l
ine 1252, in __init__
configobj.DuplicateError: Duplicate keyword name at line 16.

C:\Python25\vsjservice>tg-admin sql create
Using database URI mysql://root:password@localhost/tg
Traceback (most recent call last):
File "C:\Python25\Scripts\tg-admin-script.py", line 8, in <module>
load_entry_point('turbogears==1.0.4.2', 'console_scripts', 'tg-
admin')()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 371, in main
command.run()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 126, in run
command.the_runner.run(sys.argv)
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 101, in run
runner.run()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 307, in run
self.command()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 628, in command
for soClass in self.classes(require_some=True):
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 319, in classes
all.extend(self.classes_from_egg(egg_spec))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 487, in classes_from_egg
moduleloader.load_module(mod)))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\uti
l\moduleloader.py", line 5, in load_module
mod = __import__(module_name)
File "C:\Python25\vsjservice\vsjservice\model.py", line 18, in
<module>
class Workorder(SQLObject):
File "C:\Python25\vsjservice\vsjservice\model.py", line 22, in
Workorder
customer = ForeignKey("Customer")
NameError: name 'ForeignKey' is not defined

C:\Python25\vsjservice>easy_install SQLObject
Searching for SQLObject
Best match: sqlobject 0.10.0b1
Processing sqlobject-0.10.0b1-py2.5.egg
sqlobject 0.10.0b1 is already the active version in easy-install.pth
Installing sqlobject-admin script to C:\Python25\Scripts

Using c:\python25\lib\site-packages\sqlobject-0.10.0b1-py2.5.egg
Processing dependencies for SQLObject
Finished processing dependencies for SQLObject

C:\Python25\vsjservice>tg-admin create sql

TurboGears 1.0.4.2 command line interface

Usage: C:\Python25\Scripts\tg-admin-script.py [options] <command>

Options:
-c CONFIG --config=CONFIG Config file to use
-e EGG_SPEC --egg=EGG_SPEC Run command on given Egg

Commands:
i18n Manage i18n data
info Show version info
quickstart Create a new TurboGears project
shell Start a Python prompt with your database available
sql Run the database provider manager
toolbox Launch the TurboGears Toolbox
update Update an existing turbogears project

C:\Python25\vsjservice>tg-admin sql create
Using database URI mysql://root:password@localhost/tg
Traceback (most recent call last):
File "C:\Python25\Scripts\tg-admin-script.py", line 8, in <module>
load_entry_point('turbogears==1.0.4.2', 'console_scripts', 'tg-
admin')()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 371, in main
command.run()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 126, in run
command.the_runner.run(sys.argv)
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 101, in run
runner.run()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 307, in run
self.command()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 628, in command
for soClass in self.classes(require_some=True):
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 319, in classes
all.extend(self.classes_from_egg(egg_spec))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 487, in classes_from_egg
moduleloader.load_module(mod)))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\uti
l\moduleloader.py", line 5, in load_module
mod = __import__(module_name)
File "C:\Python25\vsjservice\vsjservice\model.py", line 18, in
<module>
class Workorder(SQLObject):
File "C:\Python25\vsjservice\vsjservice\model.py", line 22, in
Workorder
customer = ForeignKey("Customer")
NameError: name 'ForeignKey' is not defined

C:\Python25\vsjservice>tg-admin sql create
Using database URI mysql://root:password@localhost/tg
Traceback (most recent call last):
File "C:\Python25\Scripts\tg-admin-script.py", line 8, in <module>
load_entry_point('turbogears==1.0.4.2', 'console_scripts', 'tg-
admin')()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 371, in main
command.run()
File "c:\python25\lib\site-packages\TurboGears-1.0.4.2-py2.5.egg
\turbogears\co
mmand\base.py", line 126, in run
command.the_runner.run(sys.argv)
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 101, in run
runner.run()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 307, in run
self.command()
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 628, in command
for soClass in self.classes(require_some=True):
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 319, in classes
all.extend(self.classes_from_egg(egg_spec))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\man
ager\command.py", line 487, in classes_from_egg
moduleloader.load_module(mod)))
File "c:\python25\lib\site-packages\SQLObject-0.10.0b1-py2.5.egg
\sqlobject\uti
l\moduleloader.py", line 5, in load_module
mod = __import__(module_name)
File "C:\Python25\vsjservice\vsjservice\model.py", line 18, in
<module>
class Workorder(SQLObject):
File "C:\Python25\vsjservice\vsjservice\model.py", line 22, in
Workorder
customer = ForeignKey("Customer")
NameError: name 'ForeignKey' is not defined

C:\Python25\vsjservice>




Jim Steil

unread,
Feb 12, 2008, 5:38:58 PM2/12/08
to turbo...@googlegroups.com
I think you'll need to add ForeignKey to your import statement from
sqlobject.

-Jim

Florent Aide

unread,
Feb 12, 2008, 5:44:55 PM2/12/08
to turbo...@googlegroups.com
On Feb 12, 2008 11:38 PM, Jim Steil <st...@mailbag.com> wrote:

[...]

> I think you'll need to add ForeignKey to your import statement from
> sqlobject.

and you should also not post such long emails to the mailing list but
use a paster like this one to post your listings, code and debug
traces:

http://paste.turbogears.org/

Florent.

Nick Murdoch

unread,
Feb 12, 2008, 5:50:11 PM2/12/08
to turbo...@googlegroups.com
On Tue, 12 Feb 2008 22:44:55 -0000, Florent Aide <floren...@gmail.com>
wrote:

> On Feb 12, 2008 11:38 PM, Jim Steil <st...@mailbag.com> wrote:
>

> http://paste.turbogears.org/

That's a pretty cool service! Do you know what provides the syntax
highlighting on it?

hoboro

unread,
Feb 13, 2008, 10:50:40 AM2/13/08
to TurboGears
Everyone,

Thank you for your help. I got rid of the compile error from the
declaration.

Rohan
Reply all
Reply to author
Forward
0 new messages