Django

Code

Changeset 3104

Show
Ignore:
Timestamp:
06/07/06 19:13:52 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2108 -- do not try to save an empty model.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/base.py

    r3046 r3104  
    184184                    (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.order_with_respect_to.column))) 
    185185                db_values.append(getattr(self, self._meta.order_with_respect_to.attname)) 
    186             cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ 
    187                 (backend.quote_name(self._meta.db_table), ','.join(field_names), 
    188                 ','.join(placeholders)), db_values) 
    189             if self._meta.has_auto_field and not pk_set: 
    190                 setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column)) 
     186            if db_values: 
     187                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ 
     188                    (backend.quote_name(self._meta.db_table), ','.join(field_names), 
     189                    ','.join(placeholders)), db_values) 
     190                if self._meta.has_auto_field and not pk_set: 
     191                    setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column)) 
    191192        transaction.commit_unless_managed() 
    192193