Opened 12 years ago

Closed 12 years ago

#2487 closed defect (wontfix)

AttributeError: Cursor instance has no attribute 'lastrowid'

Reported by: andre@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


python syncdb errors on 'lastrowid'...

I'm new to Django... Installed version 0.95 on a linux box...Running Python 2.4 and MySQL 5.0... Every time I run python syncdb, I get an error related to 'lastrowid':

sniper:~/py/sites/testsite$ python syncdb
Creating table polls_poll
Creating table polls_choice
Traceback (most recent call last):

File "", line 11, in ?


File "/usr/lib/python2.4/site-packages/django/core/", line 1319, in execute_manag


execute_from_command_line(action_mapping, argv)

File "/usr/lib/python2.4/site-packages/django/core/", line 1243, in execute_from_



File "/usr/lib/python2.4/site-packages/django/core/", line 491, in syncdb

app=app, created_models=created_models)

File "/usr/lib/python2.4/site-packages/django/dispatch/", line 347, in send


File "/usr/lib/python2.4/site-packages/django/dispatch/", line 47, in robustAppl y

return receiver(*arguments, named)

File "/usr/lib/python2.4/site-packages/django/contrib/auth/", line 26, in create_ permissions

ctype = ContentType.objects.get_for_model(klass)

File "/usr/lib/python2.4/site-packages/django/contrib/contenttypes/", line 14, in get _for_model

model=opts.object_name.lower(), defaults={'name': str(opts.verbose_name)})

File "/usr/lib/python2.4/site-packages/django/db/models/", line 70, in get_or_create

return self.get_query_set().get_or_create(kwargs)

File "/usr/lib/python2.4/site-packages/django/db/models/", line 240, in get_or_create

File "/usr/lib/python2.4/site-packages/django/db/models/", line 211, in save

setattr(self,, backend.get_last_insert_id(cursor, self._meta.db_table,

File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/", line 125, in get_las t_insert_id

return cursor.lastrowid

File "/usr/lib/python2.4/site-packages/django/db/backends/", line 39, in getattr

return getattr(self.cursor, attr)

File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/", line 51, in getatt r

return getattr(self.cursor, attr)

AttributeError: Cursor instance has no attribute 'lastrowid'

Change History (3)

comment:1 Changed 12 years ago by Malcolm Tredinnick

What version of the Python MySQL wrapper are you using and on what OS? The Python DB API requires that the cursor object has a lastrowid attribute, so something strange is going on here. Plus this problem has never been reported before, and you're not the first person to use MySQL, so we need to work out what is different about your setup.

comment:2 Changed 12 years ago by andrwe@…


Thank you for looking into this...

I'm using MySQLdb...below is the output from help(MySQLdb). MySQL 5 was installed from the Red Hat rpm.

Do you know how to find the path of a package that python has loaded?

Also, I just tried running a few other model related methods like :

Poll.objects.all() - which gave me a different error:

File "/usr/lib/python2.4/site-packages/MySQLdb/", line 62, in execute

elif type(args) is ListType and type(args[0]) is TupleType:

IndexError: list index out of range
-- - which gives me "lastrowid" error:

File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/", line 51, in getattr

return getattr(self.cursor, attr)

AttributeError: Cursor instance has no attribute 'lastrowid'


BINARY = DBAPISet(252, 251, 250, 249)
DATE = DBAPISet(10, 14)
NUMBER = DBAPISet(0, 5, 4, 9, 3, 8, 1, 13)
STRING = DBAPISet(1, 247, 254, 253)
TIME = DBAPISet(11,)
all = ['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date'...
author = 'Andy Dustman <andy@…>'
revision = '1.11'
version = '0.9.1'
apilevel = '2.0'
paramstyle = 'format'
threadsafety = 1
version_info = (0, 9, 1, 'final', 1)



comment:3 Changed 12 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

MySQLdb-0.9.1 was released in October, 2001! Even at version 1.0 (June 2004), they weren't claiming MySQL-4.1 and later support and there were no doubt other problems as well. I think there is a limit to how old a release we are going to be able to support.

I don't normally like saying this, but please upgrade to a more recent MySQLdb package (Sourceforge page, if you can't find an RPM for your particular installation) and see if the problem still occurs. 0.9.1 is just too old to be able to make debugging and supporting worthwhile.

Note: See TracTickets for help on using tickets.
Back to Top