77👍
It’s called models.Model and not models.model (case sensitive). Fix your Poll model like this –
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
8👍
I also got the same error but I noticed that I had typed in Foreign*k*ey and not Foreign*K*ey,(capital K) if there is a newbie out there, check out spelling and caps.
- [Django]-Django: Get current user in model save
- [Django]-Django {% static 'path' %} in javascript file
- [Django]-Good open source django project for learning
3👍
Searching
AttributeError: ‘module’ object has no attribute ‘BinaryField’
landed me here.
The above answers did not solve the problem, so I’m posting my answer.
BinaryField
was added since Django 1.6. If you have an older version, it will give you the above error.
You may want to check the spelling of the attribute first, as suggested in the above answers, and then check to make sure the module in the Django version indeed has the attribute.
- [Django]-Django site with 2 languages
- [Django]-How to squash recent Django migrations?
- [Django]-How to sign in with the Google+ API using Django?
2👍
As the error message says in the last line: the module models
in the file c:\projects\mysite..\mysite\polls\models.py
contains no class model
. This error occurs in the definition of the Poll
class:
class Poll(models.model):
Either the class model
is misspelled in the definition of the class Poll
or it is misspelled in the module models
. Another possibility is that it is completely missing from the module models
. Maybe it is in another module or it is not yet implemented in models
.
- [Django]-What is actually assertEquals in Python?
- [Django]-Django sending email
- [Django]-Django i18n: Make sure you have GNU gettext tools
2👍
I realized that by looking at the stack trace it was trying to load my own script in place of another module called the same way,i.e., my script was called random.py and when a module i used was trying to import the “random” package, it was loading my script causing a circular reference and so i renamed it and deleted a .pyc file it had created from the working folder and things worked just fine.
- [Django]-How to use django-debug-toolbar on AJAX calls?
- [Django]-Django test to use existing database
- [Django]-Django – How to track if a user is online/offline in realtime?
2👍
In class poll
, you inherited your class from models.model
but there’s no module in models called that name.
Because Python is case sensitive, you need to use the capital Model
instead of model
.
class poll(models.Model):
...
- [Django]-Get all related Django model objects
- [Django]-How to create user from django shell
- [Django]-How can I set two primary key fields for my models in Django?
0👍
Change this
class Poll(models.model):
to this
class Poll(models.Model):
problem was models.model —> models.Model
- [Django]-Union and Intersect in Django
- [Django]-Django django-extensions commands unavailable ( graph_models )
- [Django]-How can I call a custom Django manage.py command directly from a test driver?
0👍
I had a similar issue. I have given from django.db import models in my admin.py file. After modifying it to from MyAppName import models, my issue is resolved. (Though I don’t understand y I am supposed to import models from my app and not django.db) Also, one more thing just verify how you have defined your primary key. Make sure to add this DEFAULT_AUTO_FIELD = ‘django.db.models.BigAutoField’ in your setting.py file if you haven’t exclusively defined your primary key.
- [Django]-Django: best practice way to get model from an instance of that model
- [Django]-Django Python rest framework, No 'Access-Control-Allow-Origin' header is present on the requested resource in chrome, works in firefox
- [Django]-Better ArrayField admin widget?