#原模型文件
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
#现模型文件
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
birth_date = models.DateField()
修改模型文件后,代码
python manage.py makemigrations
python manage.py migrate
报错,
You are trying to add a non-nullable field '----' to person without a default; we can't do that (the database needs something to populate existing rows).
。解决措施
先赋予其默认值
#第一步 赋予默认值
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
birth_date = models.DateField(default='2001-01-01')
#第二步
python manage.py makemigrations
python manage.py migrate
#第三步
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
birth_date = models.DateField()