Opened 9 years ago

Closed 9 years ago

#2487 closed defect (wontfix)

AttributeError: Cursor instance has no attribute 'lastrowid'

Reported by: andre@… Owned by: adrian
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: UI/UX:

Description

python manage.py 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 manage.py syncdb, I get an error related to 'lastrowid':

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

File "manage.py", line 11, in ?

execute_manager(settings)

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

er

execute_from_command_line(action_mapping, argv)

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

command_line

action_mapping[action]()

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

app=app, created_models=created_models)

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

sender=sender,

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

return receiver(*arguments, named)

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

ctype = ContentType.objects.get_for_model(klass)

File "/usr/lib/python2.4/site-packages/django/contrib/contenttypes/models.py", 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/manager.py", 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/query.py", line 240, in get_or_create

obj.save()

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

setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))

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

return cursor.lastrowid

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

return getattr(self.cursor, attr)

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

return getattr(self.cursor, attr)

AttributeError: Cursor instance has no attribute 'lastrowid'

Change History (3)

comment:1 Changed 9 years ago by mtredinnick

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 9 years ago by andrwe@…

Hi,

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/cursors.py", line 62, in execute

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

IndexError: list index out of range
--
p.save() - which gives me "lastrowid" error:

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

return getattr(self.cursor, attr)

AttributeError: Cursor instance has no attribute 'lastrowid'
--
help("MySQLdb"):

DATA

BINARY = DBAPISet(252, 251, 250, 249)
DATE = DBAPISet(10, 14)
NULL = 'NULL'
NUMBER = DBAPISet(0, 5, 4, 9, 3, 8, 1, 13)
ROWID = DBAPISet()
STRING = DBAPISet(1, 247, 254, 253)
TIME = DBAPISet(11,)
TIMESTAMP = DBAPISet(7, 12)
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)

VERSION

0.9.1

comment:3 Changed 9 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from new to closed

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