Django

Code

Ticket #6457 (closed: worksforme)

Opened 2 years ago

Last modified 2 years ago

Tutorial sample code: change max_length to maxlength

Reported by: musner@gmail.com Assigned to: nobody
Milestone: Component: Django Web site
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Attachments

Change History

01/25/08 11:15:54 changed by ramiro

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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]

01/25/08 13:15:55 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to worksforme.

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.


Add/Change #6457 (Tutorial sample code: change max_length to maxlength)




Change Properties
Action