Hallo,
Mike Hostetler hat gesagt: // Mike Hostetler wrote:
>
> I'm not only new to SQLObject, but to the whole DB realm in general.
>
> I made a table in PostgreSQL called Site, then I created a class not too
> dissimilar from the example in the documentation:
SQLObject can create tables on its own, and in fact that is one of the
coolest features, IMO. Somehow I alsways hated writing "create
table..." by hand, now I don't need to anymore ;)
Just call:
Site.dropTable()
Site.createTable()
> >>> class Site(SQLObject):
> ... _columns = [StringCol('url'),
> ... DateTimeCol('modified'),
> ... StringCol('etag')]
> ...
>
> But, when I tried to make a new object, it crashed:
>
> >>> s = Site.new(url=lst[0],modified=lst[1],etag=lst[2])
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line
> 713, in new
> inst._SO_finishCreate()
> File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line
> 732, in _SO_finishCreate
> id = self._connection.queryInsertID(self._table, self._idName,
> AttributeError: 'Site' object has no attribute '_connection'
> >>> Site._connection = c
What is c? Is it a PostgresConnection to your database looking like
the one in examples/people.py?
> >>> s = Site.new(url=lst[0],modified=lst[1],etag=lst[2])
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line
> 713, in new
> inst._SO_finishCreate()
> File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line
> 733, in _SO_finishCreate
> names, values)
> File "/usr/lib/python2.2/site-packages/SQLObject/DBConnection.py", line
> 126, in queryInsertID
> return self._runWithConnection(self._queryInsertID, table, idName,
> names, values)
> File "/usr/lib/python2.2/site-packages/SQLObject/DBConnection.py", line
> 72, in _runWithConnection
> val = meth(conn, *args)
> File "/usr/lib/python2.2/site-packages/SQLObject/DBConnection.py", line
> 437, in _queryInsertID
> c.execute('SELECT nextval(\'%s_id_seq\')' % table)
> psycopg.ProgrammingError: ERROR: Relation "site_id_seq" does not exist
>
> SELECT nextval('site_id_seq')
>
> Can anyone shed some light on a poor newbie?
You might want to try to let SQLObject create the table, than look at
the created schema with for example pg_dump.
ciao
--
Frank Barknecht _ ______footils.org__
|