title: How to get the primary key id that is auto generated in Django Models
body: <p>I have a DB Schema that I have inherited from some legacy code. Now we intend to use Django to reflect the tables into models. This means I cannot have the tables be generated using the django models. The table schema looks like so:-</p>
  
  <pre><code>mysql&gt; desc student_profile;
  +-------------+-------------+------+-----+---------+----------------+
  | Field       | Type        | Null | Key | Default | Extra          |
  +-------------+-------------+------+-----+---------+----------------+
  | id          | int(11)     | NO   | PRI | NULL    | auto_increment |
  | joining_on  | datetime    | YES  |     | NULL    |                |
  | brothername | varchar(45) | YES  |     | NULL    |                |
  +-------------+-------------+------+-----+---------+----------------+
  3 rows in set (0.01 sec)
  </code></pre>
  
  <p>Now the Django model that I have created for this schema looks like this:-</p>
  
  <pre><code>class StudentProfile(models.Model):
      id=models.IntegerField(primary_key=True)
      joining_on=models.DateField()
      brothername=models.CharField(max_length=45)
  
      class Meta:
          db_table="student_profile"
  </code></pre>
  
  <p>When I insert a row into this, like so:-</p>
  
  <pre><code>StudentProfile.objects.insert(brothername="Bro")
  </code></pre>
  
  <p>The row is correctly inserted. But I do not have a way to extract the id field. It appears that since this field is not an <code>AutoField</code>, django does not copy over the id that was automatically generated by MySql. What can I do to obtain the <code>id</code> value with which the row was created? I checked (<a href="https://code.djangoproject.com/ticket/8799#comment:1" rel="noreferrer">https://code.djangoproject.com/ticket/8799#comment:1</a>), and this appears to be by design. But I still need a way to get to the <code>id</code> and have it be reflected in the <code>StudentProfile</code> model. What can I do?</p>
  
  <p>One solution could be to override the default <code>save()</code> and explicitly provide the <code>id</code> into the <code>save()</code> of the model. But is that the right way? The database (it is MySql) provides a way to generate the id, and I must be able to use this fact to my advantage rather than having to maintain a running counter by the application. Any hints?</p>