Commits

Andrew Godwin  committed 9521637 Merge

Merged in shaib/south (pull request #124)

Fixes for 3 backends

  • Participants
  • Parent commits e495d75, abbdca1

Comments (0)

Files changed (3)

File south/db/generic.py

             sqls.append((self.alter_string_drop_null % params, []))
 
         # Do defaults
-        self._alter_set_defaults(field, name, params, sqls)
+        #self._alter_set_defaults(field, name, params, sqls)
 
         # Actually change the column (step 1 -- Nullity may need to be fixed)
         if self.allows_combined_alters:

File south/db/sqlite3.py

         field_default = None
         if not getattr(field, '_suppress_default', False):
             default = field.get_default()
-            if default is not None and default!='':
+            if default is not None:
                 field_default = "'%s'" % field.get_db_prep_save(default, connection=self._get_connection())
         field._suppress_default = True
         self._remake_table(table_name, added={
                 continue
             src_fields_new.append(self.quote_name(field))
         for field, (_,default) in added.items():
-            if default is not None and default!='':
+            if default is not None:
                 field = self.quote_name(field)
                 src_fields_new.append("%s as %s" % (default, field))
                 dst_fields_new.append(field)

File south/tests/db.py

         db.execute("INSERT INTO test_altercd (eggs) values (12)")
         null = db.execute("SELECT spam FROM test_altercd")[0][0]
         self.assertFalse(null, "Default for char field was installed into database")
+
+    @skipIf('oracle' in db.backend_name, "Oracle does not differentiate empty trings from null")
+    def test_default_empty_string(self):
+        """
+        Test altering column defaults with char fields
+        """
+        db.create_table("test_cd_empty", [
+            ('spam', models.CharField(max_length=30, default='')),
+            ('eggs', models.CharField(max_length=30)),
+        ])
+        # Create a record
+        db.execute("INSERT INTO test_cd_empty (spam, eggs) values ('1','2')")
+        # Add a column
+        db.add_column("test_cd_empty", "ham", models.CharField(max_length=30, default=''))
+        
+        empty = db.execute("SELECT ham FROM test_cd_empty")[0][0]
+        self.assertEquals(empty, "", "Empty Default for char field isn't empty string")
         
     def test_mysql_defaults(self):
         """
             db.execute("INSERT INTO test_alter_unique2 (spam, eggs) VALUES (1, 42)")
         except:
             self.fail("Looks like multi-field unique constraint applied to only one field.")
+        db.rollback_transaction()
         db.start_transaction()
-        db.rollback_transaction()
         try:
             db.execute("INSERT INTO test_alter_unique2 (spam, eggs) VALUES (0, 43)")
         except:
         except:
             pass
         else:
-            self.fail("Could insert the same integer twice into a unique field.")
+            self.fail("Could insert the same pair twice into unique-together fields.")
         db.rollback_transaction()
         # Altering one column should not drop or modify multi-column constraint
-        db.alter_column("test_alter_unique2", "eggs", models.CharField(max_length=10))
+        db.alter_column("test_alter_unique2", "eggs", models.PositiveIntegerField())
         db.start_transaction()
         try:
             db.execute("INSERT INTO test_alter_unique2 (spam, eggs) VALUES (1, 42)")
         except:
             self.fail("Altering one column broken multi-column unique constraint.")
+        db.rollback_transaction()
         db.start_transaction()
-        db.rollback_transaction()
         try:
             db.execute("INSERT INTO test_alter_unique2 (spam, eggs) VALUES (0, 43)")
         except:
         except:
             pass
         else:
-            self.fail("Could insert the same integer twice into a unique field after alter_column with unique=False.")
+            self.fail("Could insert the same pair twice into unique-together fields after alter_column with unique=False.")
         db.rollback_transaction()
         db.delete_table("test_alter_unique2")
         db.start_transaction()