python - Can't do migrations - ... has no field named 'questions' -
i'm trying figure out why django return's error when trying migrate
after makemigrations
. tried change related names , delete last migrations nothing works.
maybe see what's problem?
error after migrate: django.core.exceptions.fielddoesnotexist: languagequizsitting has no field named 'questions'
models.py
from django.db import models solutionsforlanguagesapp import models sfl_models jsonfield import jsonfield import random class languagequiz(models.model): name = models.charfield(max_length=40) language = models.onetoonefield(sfl_models.language) class question(models.model): language_quiz = models.foreignkey(languagequiz,related_name='questions') text = models.textfield() class answer(models.model): question = models.foreignkey(question,related_name='answers') text = models.textfield() correct = models.booleanfield() class languagequizsitting(models.model): user = models.onetoonefield(sfl_models.user) quiz = models.onetoonefield(languagequiz) date_opened = models.datetimefield(auto_created=true) date_closed = models.datetimefield(null=true) max_questions = models.integerfield() def load_questions(self): questions = random.sample(self.quiz.questions,self.max_questions) question in questions: sittingquestion.objects.create(question=question,sitting=self) def get_next_question(self): q = self.questions.filter(answered=0) if len(q)>0: return q[0] else: return false class sittingquestion(models.model): sitting = models.foreignkey(languagequizsitting,related_name='questions',on_delete=models.cascade) question = models.foreignkey(question, related_name='sittingquestions') answered = models.booleanfield(default=0) result = models.booleanfield(default=0)
last migration
class migration(migrations.migration): dependencies = [ ('language_tests', '0001_initial'), ] operations = [ migrations.alterfield( model_name='question', name='language_quiz', field=models.foreignkey(related_name='questions', to='language_tests.languagequiz'), ), migrations.alterfield( model_name='sittingquestion', name='question', field=models.foreignkey(related_name='sitting_questions', to='language_tests.question'), ), migrations.alterfield( model_name='sittingquestion', name='sitting', field=models.foreignkey(related_name='questions', to='language_tests.languagequizsitting'), ), ]
traceback:
(venv) c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2>python manage.py migrate operations perform: synchronize unmigrated apps: essay, smart_selects, true_false, super_inlines, staticfiles, multichoice, messages, nested_inline, quiz, django_extensions, django_tables2, constance, crispy_forms apply migrations: language_tests, database, admin, sessions, auth, contenttypes, solutionsforlanguagesapp synchronizing apps without migrations: creating tables... running deferred sql... installing custom sql... running migrations: rendering model states... done applying language_tests.0002_auto_20160711_1524...traceback (most recent call last): file "manage.py", line 10, in <module> execute_from_command_line(sys.argv) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line utility.execute() file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv self.execute(*args, **cmd_options) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\core\management\base.py", line 445, in execute output = self.handle(*args, **options) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\core\management\commands\migrate.py", line 222, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\migrations\executor.py", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\migrations\executor.py", line 148, in apply_migration state = migration.apply(state, schema_editor) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\migrations\migration.py", line 115, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\migrations\operations\fields.py", line 201, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\backends\base\schema.py", line 484, in alter_field old_db_params, new_db_params, strict) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 203, in _alter_field self._remake_table(model, alter_fields=[(old_field, new_field)]) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\backends\sqlite3\schema.py", line 140, in _remake_table self.create_model(temp_model) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\backends\base\schema.py", line 236, in create_model definition, extra_params = self.column_sql(model, field) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\backends\base\schema.py", line 135, in column_sql db_params = field.db_parameters(connection=self.connection) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 2010, in db_parameters return {"type": self.db_type(connection), "check": []} file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 2001, in db_type rel_field = self.related_field file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 1904, in related_field return self.foreign_related_fields[0] file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 1638, in foreign_related_fields return tuple(rhs_field lhs_field, rhs_field in self.related_fields if rhs_field) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 1625, in related_fields self._related_fields = self.resolve_related_fields() file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\fields\related.py", line 1618, in resolve_related_fields else self.rel.to._meta.get_field(to_field_name)) file "c:\users\milano\pycharmprojects\futilestudio\solutionsforlanguages_2\venv\lib\site-packages\django\db\models\options.py", line 554, in get_field raise fielddoesnotexist('%s has no field named %r' % (self.object_name, field_name)) django.core.exceptions.fielddoesnotexist: languagequizsitting has no field named 'questions'
so matter following one:
questions = random.sample(self.quiz.questions,self.max_questions)
self.quiz go there :
quiz = models.onetoonefield(languagequiz)
and quiz.questions go there :
class languagequiz(models.model): name = models.charfield(max_length=40) language = models.onetoonefield(sfl_models.language)
the matter questions doesn't exist in languagequiz.
Comments
Post a Comment