Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2108 -- allow saving of empty models, rather than just droppin…

…g them.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3115 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7e2b888a2d3e745dea551285fac6e88e409fe18d 1 parent 29f55c8
Malcolm Tredinnick authored June 08, 2006
3  django/db/backends/ado_mssql/base.py
@@ -131,6 +131,9 @@ def get_fulltext_search_sql(field_name):
131 131
 def get_drop_foreignkey_sql():
132 132
     return "DROP CONSTRAINT"
133 133
 
  134
+def get_pk_default_value():
  135
+    return "DEFAULT"
  136
+
134 137
 OPERATOR_MAPPING = {
135 138
     'exact': '= %s',
136 139
     'iexact': 'LIKE %s',
3  django/db/backends/mysql/base.py
@@ -158,6 +158,9 @@ def get_fulltext_search_sql(field_name):
158 158
 def get_drop_foreignkey_sql():
159 159
     return "DROP FOREIGN KEY"
160 160
 
  161
+def get_pk_default_value():
  162
+    return "DEFAULT"
  163
+
161 164
 OPERATOR_MAPPING = {
162 165
     'exact': '= %s',
163 166
     'iexact': 'LIKE %s',
3  django/db/backends/oracle/base.py
@@ -114,6 +114,9 @@ def get_fulltext_search_sql(field_name):
114 114
 def get_drop_foreignkey_sql():
115 115
     return "DROP FOREIGN KEY"
116 116
 
  117
+def get_pk_default_value():
  118
+    return "DEFAULT"
  119
+
117 120
 OPERATOR_MAPPING = {
118 121
     'exact': '= %s',
119 122
     'iexact': 'LIKE %s',
3  django/db/backends/postgresql/base.py
@@ -108,6 +108,9 @@ def get_fulltext_search_sql(field_name):
108 108
 def get_drop_foreignkey_sql():
109 109
     return "DROP CONSTRAINT"
110 110
 
  111
+def get_pk_default_value():
  112
+    return "DEFAULT"
  113
+
111 114
 # Register these custom typecasts, because Django expects dates/times to be
112 115
 # in Python's native (standard-library) datetime/time format, whereas psycopg
113 116
 # use mx.DateTime by default.
3  django/db/backends/postgresql_psycopg2/base.py
@@ -114,6 +114,9 @@ def get_fulltext_search_sql(field_name):
114 114
 def get_drop_foreignkey_sql():
115 115
     return "DROP CONSTRAINT"
116 116
 
  117
+def get_pk_default_value():
  118
+    return "DEFAULT"
  119
+
117 120
 OPERATOR_MAPPING = {
118 121
     'exact': '= %s',
119 122
     'iexact': 'ILIKE %s',
3  django/db/backends/sqlite3/base.py
@@ -130,6 +130,9 @@ def get_fulltext_search_sql(field_name):
130 130
 def get_drop_foreignkey_sql():
131 131
     return ""
132 132
 
  133
+def get_pk_default_value():
  134
+    return "NULL"
  135
+
133 136
 def _sqlite_date_trunc(lookup_type, dt):
134 137
     try:
135 138
         dt = util.typecast_timestamp(dt)
6  django/db/models/base.py
@@ -189,6 +189,12 @@ def save(self):
189 189
                     ','.join(placeholders)), db_values)
190 190
                 if self._meta.has_auto_field and not pk_set:
191 191
                     setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
  192
+            else:
  193
+                # Create a new record with defaults for everything.
  194
+                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" %
  195
+                    (backend.quote_name(self._meta.db_table), 
  196
+                     backend.quote_name(self._meta.pk.column),
  197
+                     backend.get_pk_default_value()))
192 198
         transaction.commit_unless_managed()
193 199
 
194 200
         # Run any post-save hooks.

0 notes on commit 7e2b888

Please sign in to comment.
Something went wrong with that request. Please try again.