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