Hi,
I'm am trying to follow along with the tutorial, but keep getting this
error when I migrate the models. Here is my models.py file for the polls
app:
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
Then, when I use the makemigrations and migrate commands, I get this error:
Operations to perform:
Apply all migrations: auth, admin, sessions, contenttypes, polls
Running migrations:
Applying polls.0001_initial...Traceback (most recent call last):
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/options.py",
line 414, in get_field_by_name
return self._name_map[name]
AttributeError: 'Options' object has no attribute '_name_map'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/options.py",
line 417, in get_field_by_name
return cache[name]
KeyError: <class 'polls.models.Question'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/core/management/__init__.py",
line 385, in execute_from_command_line
utility.execute()
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/core/management/__init__.py",
line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/core/management/base.py",
line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/core/management/base.py",
line 338, in execute
output = self.handle(*args, **options)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/core/management/commands/migrate.py",
line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/migrations/executor.py",
line 63, in migrate
self.apply_migration(migration, fake=fake)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/migrations/executor.py",
line 97, in apply_migration
migration.apply(project_state, schema_editor)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/migrations/migration.py",
line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state,
new_state)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/migrations/operations/fields.py",
line 37, in database_forwards
field,
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/backends/sqlite3/schema.py",
line 167, in add_field
self._remake_table(model, create_fields=[field])
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/backends/sqlite3/schema.py",
line 128, in _remake_table
self.create_model(temp_model)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/backends/schema.py",
line 209, in create_model
definition, extra_params = self.column_sql(model, field)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/backends/schema.py",
line 112, in column_sql
db_params = field.db_parameters(connection=self.connection)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1784, in db_parameters
return {"type": self.db_type(connection), "check": []}
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1775, in db_type
rel_field = self.related_field
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1681, in related_field
return self.foreign_related_fields[0]
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1439, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields)
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1426, in related_fields
self._related_fields = self.resolve_related_fields()
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/fields/related.py",
line 1419, in resolve_related_fields
else self.rel.to._meta.get_field_by_name(to_field_name)[0])
File
"/Users/derekng/Documents/projects/django-tutorial/lib/python3.4/site-packages/django/db/models/options.py",
line 420, in get_field_by_name
% (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Question has no field named <class
'polls.models.Question'>
I can't figure out what I am doing wrong. I tried googling, but to no avail.
Thanks in advanced,
Derek
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/cd1da3b8-d37e-4f7d-ab01-bfc0056d6af8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.