Opened 17 years ago

Closed 17 years ago

Last modified 11 years ago

#6457 closed Uncategorized (worksforme)

Tutorial sample code: change max_length to maxlength

Reported by: musner@… Owned by: nobody
Component: *.djangoproject.com Version: dev
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

Description

While working through the tutorial, I reached the section where you modify the polls/models.py file.
I got a max_length error (running development code (rev 7028)):

>python manage.py sql polls

mysite.polls: __init__() got an unexpected keyword argument 'max_length'
1 error found.
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "c:\Python25\lib\site-packages\django\core\management.py", line 1672, in
execute_manager
    execute_from_command_line(action_mapping, argv)
  File "c:\Python25\lib\site-packages\django\core\management.py", line 1620, in
execute_from_command_line
    mod_list = [models.get_app(app_label) for app_label in args[1:]]
  File "c:\Python25\lib\site-packages\django\db\models\loading.py", line 40, in
get_app
    mod = load_app(app_name)
  File "c:\Python25\lib\site-packages\django\db\models\loading.py", line 51, in
load_app
    mod = __import__(app_name, {}, {}, ['models'])
  File "C:\Documents and Settings\usner\Desktop\django\mysite\..\mysite\polls\mo
dels.py", line 3, in <module>
    class Poll(models.Model):
  File "C:\Documents and Settings\usner\Desktop\django\mysite\..\mysite\polls\mo
dels.py", line 4, in Poll
    question = models.CharField(max_length=200)
TypeError: __init__() got an unexpected keyword argument 'max_length'

After removing 'max_length=' from the code to see what happened, I received the following error:

>python manage.py sql polls

polls.poll: "question": CharFields require a "maxlength" attribute.
polls.choice: "choice": CharFields require a "maxlength" attribute.
2 errors found.

The tutorial still has the underscore in max_length in the sample code.
After removing it, it worked.

Solution:
Make the following change to the sample code (max_length -> maxlength):

from django.db import models

class Poll(models.Model):
    question = models.CharField(maxlength=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(maxlength=200)
    votes = models.IntegerField()

Thanks,
Mike

Change History (3)

comment:1 by Ramiro Morales, 17 years ago

Are you sure the Django version you are using (i.e. the one at c:\Python25\lib\site-packages\django\) is actually SVN r7028 and not an older one? the conversion from maxlength to max_length was commited on [5803]

comment:2 by James Bennett, 17 years ago

Resolution: worksforme
Status: newclosed

You are not actually using revision 7028; if you were you would not be receiving this error. Remove any older versions of Django you might have had installed and try again; if you continue to experience problems post a question to the django-suers mailing lists, which provides support for these sorts of issues.

comment:3 by anonymous, 11 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

none of them seems to work for me! django 1.6 and python 2.7.5

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