简体   繁体   中英

I can't figure out why my makemigrations isn't working in django,its showing following error

here is my models.py file

from django.db import models



class Question(models.Model):
    question_text = models.CharField("question",max_length=200)
    pub_date = models.DateTimeField('date published')

    #def __str__(self):
        #return self.question_text


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

Here are the screenshots of errors

Here is screenshot of my cmd

Please help me to rectify this problem.

Looking at your screenshot it seems, you did select 2nd option but never really added the default value here.

It seems you already had Choice model and then later you added choice_text field. The database need to add this column in the choice table so either you provide a default value or you choose to go with null=True

Add a default value to choice_field in Choice model:

choice_text = models.CharField(max_length=200, default='your default value')

Or,

choice_text = models.CharField(max_length=200, null=True) 

您的控制台说清楚了

Your console clearly says,add some default value to choice_text field,this is happening because u may already have some data in Choice Model/Table and after migration when new non-nullable column is created ,it either wants to set default value from console or from python code :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM