Hi Rishu,

keyed table support is only available for DB2, MS-SQL, Ingres and
Informix so far, as noted in
http://web2py.com/book/default/chapter/06#Legacy-Databases-and-Keyed-Tables

but you can contribute to web2py by adding support for mysql by
following point (E) at the bottom of
http://groups.google.com/group/web2py/msg/c9848792a8999c5f

you can always ask for help here if you get stuck.

Alternatively, and if your 'sno' field is an auto-increment field you
can use it as id by changing its definition
Field('sno','id', ...)
(see the same book section as above).

Denes.


On Nov 13, 7:39 pm, Rishu <[email protected]> wrote:
> Hi all,
> I have a project in which I am supposed to use mysql. The database
> already made up. I am facing an issue with the primary key check.
> Whensover i insert a duplicate value for the primary key i end up with
> a ticket rather than a graceful handling.
> Here's the db model:
>
> db.define_table('document',
>
> Field('sno','integer',requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'document.sno')]),
>     Field('doc_no','string',requires=[IS_NOT_EMPTY()]),
>     Field('issue','date',requires=[IS_NOT_EMPTY()]),
>     Field('expiry','date',requires=[IS_NOT_EMPTY()]),
>     Field('summary','text'),
>     primarykey=['sno'],
>     migrate=False,
>     )
>
> and the error that i receive when duplicating is :
>
> Traceback (most recent call last):
>   File "/home/paresh/web2py/gluon/restricted.py", line 188, in
> restricted
>     exec ccode in environment
>   File "/home/paresh/web2py/applications/DB/controllers/appadmin.py",
> line 410, in <module>
>   File "/home/paresh/web2py/gluon/globals.py", line 96, in <lambda>
>     self._caller = lambda f: f()
>   File "/home/paresh/web2py/applications/DB/controllers/appadmin.py",
> line 125, in insert
>     if form.accepts(request.vars, session):
>   File "/home/paresh/web2py/gluon/sqlhtml.py", line 1135, in accepts
>     pk = self.table.insert(**fields)
>   File "/home/paresh/web2py/gluon/sql.py", line 2566, in insert
>     return Table.insert(self,**fields)
>   File "/home/paresh/web2py/gluon/sql.py", line 2037, in insert
>     self._db._execute(query)
>   File "/home/paresh/web2py/gluon/sql.py", line 989, in <lambda>
>     self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
>   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in
> execute
>     self.errorhandler(self, exc, value)
>   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35,
> in defaulterrorhandler
>     raise errorclass, errorvalue
> IntegrityError: (1062, "Duplicate entry '1-1' for key 'PRIMARY'")
>
> I would like to know that do i need to handle the integrity constraint
> myself or am i missing on some point....
>
> Thanks for the help

Reply via email to