[Django]-Django – does not save to database immediately


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.


use this instead of manually calling save()

page = BlogPost.objects.create(title = page_name,body = content,
author = request.user, category = postCategory)

Leave a comment