mirror of https://github.com/django/django.git
Fixed the empty model saving case so that it retrieves the primary key id. Also
updated the tests to test this case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bff39bfb8c
commit
686c5a2f88
|
@ -187,14 +187,14 @@ class Model(object):
|
|||
cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
|
||||
(backend.quote_name(self._meta.db_table), ','.join(field_names),
|
||||
','.join(placeholders)), db_values)
|
||||
if self._meta.has_auto_field and not pk_set:
|
||||
setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
|
||||
else:
|
||||
# Create a new record with defaults for everything.
|
||||
cursor.execute("INSERT INTO %s (%s) VALUES (%s)" %
|
||||
(backend.quote_name(self._meta.db_table),
|
||||
backend.quote_name(self._meta.pk.column),
|
||||
backend.get_pk_default_value()))
|
||||
if self._meta.has_auto_field and not pk_set:
|
||||
setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
|
||||
transaction.commit_unless_managed()
|
||||
|
||||
# Run any post-save hooks.
|
||||
|
|
|
@ -12,10 +12,13 @@ class Empty(models.Model):
|
|||
|
||||
API_TESTS = """
|
||||
>>> m = Empty()
|
||||
>>> m.id
|
||||
>>> m.save()
|
||||
>>> m2 = Empty()
|
||||
>>> m2.save()
|
||||
>>> len(Empty.objects.all())
|
||||
2
|
||||
>>> m.id is not None
|
||||
True
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue