Why doesn't self.object in a CreateView have an id after saving to the database?

て烟熏妆下的殇ゞ 提交于 2019-12-05 09:44:21

It's blank because the object is not actually receiving an id. That's because the id field should be an AutoField, not IntegerField, so that it is declared as auto-incrementing.

Actually though you should not declare it at all: an primary key AutoField named id is the default, so you should leave it out.

Note you'll need to migrate your database table, or drop and recreate it, after you make this change.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!