[Django]-MySQL + Django: No obj.id after save()

6👍

✅

As Rebus says in the comments, you don’t need to define the primary key explicitly. But if you do, you must make sure it is an autoincrement field – ie AutoField – not a basic IntegerField as you have. The way you have it, there’s no way to get a new ID, which is why it’s blank on save.

0👍

System generated database keys must be set by the database or else you won’t have a multi-user database.

Leave a comment