djangobook.com, chapter 5, __init__() got an unexpected keyword argument 'maxlength'

3,593 views
Skip to first unread message

djan

unread,
Dec 1, 2008, 12:04:04 AM12/1/08
to Django users
Hello,

I'm following along with djangobook.com, and I have a problem in
chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
with MySQL).

When I run the following:
$ python manage.py validate

I receive:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/__init__.py", line 340, in execute_manager
utility.execute()
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/base.py", line 219, in execute
output = self.handle(*args, **options)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/base.py", line 348, in handle
return self.handle_noargs(**options)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/commands/validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/base.py", line 246, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib64/python2.5/site-packages/django/core/
management/validation.py", line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib64/python2.5/site-packages/django/db/models/
loading.py", line 128, in get_app_errors
self._populate()
File "/usr/local/lib64/python2.5/site-packages/django/db/models/
loading.py", line 57, in _populate
self.load_app(app_name, True)
File "/usr/local/lib64/python2.5/site-packages/django/db/models/
loading.py", line 72, in load_app
mod = __import__(app_name, {}, {}, ['models'])
File "$HOME/djcode/mysite/books/models.py", line 3, in <module>
class Publisher(models.Model):
File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
name = models.CharField(maxlength=30)
TypeError: __init__() got an unexpected keyword argument 'maxlength'


I've copied and pasted the examples for models.py as on the website,
and I have the following in settings.py:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '$HOME/djcode/prototype.sqlite'
# DATABASE_USER = '' # Not used with sqlite3.
# DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
DATABASE_PORT = ''

Any thoughts? Thanks in advance for any help.


Malcolm Tredinnick

unread,
Dec 1, 2008, 1:48:39 AM12/1/08
to django...@googlegroups.com

On Sun, 2008-11-30 at 21:04 -0800, djan wrote:
> Hello,
>
> I'm following along with djangobook.com, and I have a problem in
> chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> with MySQL).

The Django book was writting for Django 0.96. There have been a number
of backwards-incompatible changed in the period between that and Django
1.0 (which is why we held off calling earlier versions 1.0: 1.0 provides
quite good backwards compatibility assurances).

You'll need to read the book in conjunction with this document:
http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/ (and
the pages it links to).

Regards,
Malcolm


Russell Keith-Magee

unread,
Dec 1, 2008, 1:51:05 AM12/1/08
to django...@googlegroups.com
On Mon, Dec 1, 2008 at 2:04 PM, djan <lyn...@gmail.com> wrote:
>
> Hello,
>
> I'm following along with djangobook.com, and I have a problem in
> chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> with MySQL).

> TypeError: __init__() got an unexpected keyword argument 'maxlength'

The Django book is based on Django Version 0.96; we have since
released Version 1.0, which introduced a few backwards
incompatibilities - in this case, the 'maxlength' was renamed to
'max_length' for consistency with other parts of Django.

A guide to porting 0.96 applications to 1.0 can be found here:

http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/

A full list of backwards incompatibilities between version 0.96 and
1.0 can be found here:

http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges

Yours,
Russ Magee %-)

Roland van Laar

unread,
Dec 1, 2008, 3:01:36 AM12/1/08
to django...@googlegroups.com
djan wrote:
> Hello,
>
> I'm following along with djangobook.com, and I have a problem in
> chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> with MySQL).
>
> <snip>

> File "$HOME/djcode/mysite/books/models.py", line 3, in <module>
> class Publisher(models.Model):
> File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
> name = models.CharField(maxlength=30)
> TypeError: __init__() got an unexpected keyword argument 'maxlength

The book is a bit outdated, maxlength should become max_length
please do read: http://docs.djangoproject.com/en/dev/
and: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
for more information about django and the changes in 1.0

Regards,

Roland van Laar

Praveen

unread,
Dec 1, 2008, 3:57:56 AM12/1/08
to Django users
write max_length instead of maxlength

djan

unread,
Dec 1, 2008, 11:09:10 AM12/1/08
to Django users
Thank you all! This did the trick, and I'm sure it will help be avoid
future problems.

dscher

unread,
Jan 26, 2009, 4:35:18 AM1/26/09
to Django users
Thanks, this one tripped me up as well.

On Dec 2 2008, 12:09 am, djan <lyn...@gmail.com> wrote:
> Thank you all! This did the trick, and I'm sure it will help be avoid
> future problems.
>
> On Dec 1, 9:57 am, Praveen <praveen.python.pl...@gmail.com> wrote:
>
> > write max_length instead of maxlength
>
> > On Dec 1, 1:01 pm, Roland van Laar <rol...@micite.net> wrote:
>
> > > djan wrote:
> > > > Hello,
>
> > > > I'm following along with djangobook.com, and I have a problem in
> > > > chapter 5 that I cannot resolve. I am using OpenSuSE-11.0, Python
> > > > 2.5.2, sqlite3-3.5.7-17.1 (and incidentally, this same error occurs
> > > > with MySQL).
>
> > > > <snip>
> > > >   File "$HOME/djcode/mysite/books/models.py", line 3, in <module>
> > > >     class Publisher(models.Model):
> > > >   File "$HOME/djcode/mysite/books/models.py", line 4, in Publisher
> > > >     name = models.CharField(maxlength=30)
> > > >TypeError:__init__()gotanunexpectedkeywordargument'maxlength

Nkansah Rexford

unread,
Jul 8, 2013, 7:25:20 PM7/8/13
to django...@googlegroups.com
Several years since this question was asked, but really solved my problem today. I'm using 1.5 of django, and the maxlength (now max_length) thing was bugging me. 

Thanks
Reply all
Reply to author
Forward
0 new messages