Django help: AttributeError: 'module' object does not have 'Charfield' attribute

I saw several similar entries of other attributes, but not this. New for Python and Django. I made the first part of several tutorials, including the Django polls tutorial, and when it comes to the point where I syncdb for my application, I invariably get an AttributeError: 'module' object that does not have a CharField attribute.

In the models, I copied exactly as the textbook says:

from django.db import models

class Poll(models.Model): question = models.Charfield(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() # Create your models here. 

'polls' is also added to installed applications, and I use sqlite3, windows 7, python 2.7.

Any help is much appreciated! (I really try to learn!)

+9
source share
6 answers

This is a CharField , with an uppercase 'f', not a CharField , as in your code.

+42
source

I think in forms.py you use

 from django.forms import forms 

Please use this

 from django import forms 
+9
source

I have the same error, but the following code works for me:

 from django.db import models #Create your models here. class Question(models.Model): question_text = models.CharField(max_length=100) pub_date = models.DateTimeField('date published') class Choice(models.Model): choice_text = models.CharField(max_length = 200) votes = models.IntegerField(default =0) question = models.ForeignKey(Question, on_delete=models.CASCADE) 

Just change charfield () to charField () ..

0
source

change charfield to:

 CharField(max_length = 10) 

both C and F must be uppercase

0
source

In Poll CharField spelling CharField incorrectly formatted. Those. you wrote the small letter f instead of the capital letter F So, replace Charfield with CharField . You can see the code below:

 from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() 
0
source

Use it from django.db import models

0
source

All Articles