Issues with activating models in Django
Question: I'm following this tutorial
<https://docs.djangoproject.com/en/1.9/intro/tutorial02/> to learn Django.
Here is the code for my model.py file.

    
    
    from __future__ import unicode_literals
    
    from django.db import models
    
    # Create your models here
    
    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, on_delete=models.CASCADE)
        choice_text = models.CharField(max_length=200)
        votes = models.IntegerField(default=0)
    

When I run the following command:

    
    
    python manage.py makemigrations polls
    

I see that only the model question is being created and not the model choice.
When I try to the edit the model.py file and rerun the 'makemigration polls'
command, I get the following error:

    
    
    You are trying to add a non-nullable field 'pub_date' to question without a default; we can't do that (the database needs something to populate existing rows).
    Please select a fix:
     1) Provide a one-off default now (will be set on all existing rows)
     2) Quit, and let me add a default in models.py
    Select an option: 
    

I'm not sure what's wrong with the code here. Can someone please help me out?


Answer: You've got out of sync. Delete your database file, and the Python files under
polls/migrations, and run makemigrations again.

This was caused by you not having the pub_date field when you initially
migrated. There are ways of fixing this, but for the purposes of the tutorial,
you should just start again.

