5👍
✅
Remove the id
field from your Model class.
Django will insert an AutoField called id
automatically if you don’t specify a primary key, so you don’t need it.
Because you have specifically said that your id
field is an integer primary key, Django is expecting you to manage it yourself. It’s an IntField
, as you declared, not an AutoField
, so it is not automatically assigned any value.
0👍
use this instead of manually calling save()
page = BlogPost.objects.create(title = page_name,body = content,
author = request.user, category = postCategory)
Source:stackexchange.com