Интересно, что вызывает эту ошибку, удалил папку переноса, затем снова выполнил makemigrations todolist
и migrate
. Сохранено null=True
, все эти усилия напрасны
models.py
class Category(models.Model):
name = models.CharField(max_length=100)
class Meta:
verbose_name = ("Category")
verbose_name_plural = ("Categories")
def __str__(self):
return self.name
class ToDoList(models.Model):
title = models.CharField(max_length=200)
content = models.CharField(max_length=500)
created_on = models.DateField(default=timezone.now().strftime("%Y-%m-%d"))
due_date = models.DateField(default=timezone.now().strftime("%Y-%m-%d"))
category = models.ForeignKey(Category,on_delete=models.DO_NOTHING,default="general",null=True, blank=True) //kept blank and null field true
class Meta:
ordering = ["-created_on"]
def __str__(self):
return self.title
views.py
def index(request):
ToDos = ToDoList.objects.all()
catogories = Category.objects.all()
if request.method == 'POST':
if "taskAdd" in request.POST:
title = request.POST["description"]
category = request.POST["category_select"]
date = str(request.POST["date"])
content = title + "--" + date + "--" + category
ToDo = ToDoList(
title = title,
content = content,
due_date = date,
category = Category.objects.get(name=category),
)
ToDo.save()
return redirect("/")
if "taskDelete" in request.POST:
checkboxlist = request.POST["checkedbox"]
for todo_id in checkboxlist:
todo = ToDoList.objects.get(id=int(todo_id))
todo.delete()
return render(request,"index.html",{"ToDos" : ToDos,"catogories" : catogories})
0001_initaly.py // код миграции
migrations.CreateModel(
name='ToDoList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('content', models.CharField(max_length=500)),
('created_on', models.DateField(default='2020-03-29')),
('due_date', models.DateField(default='2020-03-29')),
('category', models.ForeignKey(blank=True, default='general', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='todolist.Category')),
],
options={
'ordering': ['-created_on'],
},
),
error pic
admin / todolist pi c //, который не содержит проверенное поле
заранее спасибо