Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed 1d031a3

Fix for #63: Use predictable names for UNIQUE indexes.

  • Participants
  • Parent commits 3f71fd2

Comments (0)

Files changed (2)

File db/generic.py

             if field.primary_key:
                 field_output.append('PRIMARY KEY')
             elif field.unique:
-                field_output.append('UNIQUE')
+                # Instead of using UNIQUE, add a unique index with a predictable name
+                self.add_deferred_sql(
+                    self.create_index_sql(
+                        table_name,
+                        [field.column],
+                        unique = True,
+                        db_tablespace = tablespace,
+                    )
+                )
 
             tablespace = field.db_tablespace or tablespace
             if tablespace and connection.features.supports_tablespaces and field.unique:
 
     def setUp(self):
         db.debug = False
+        db.clear_deferred_sql()
 
     def test_create(self):
         """
             ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
             ('UNIQUE', models.ForeignKey(Test)),
         ])
+        db.execute_deferred_sql()
         db.rollback_transaction()
     
     def test_rename(self):
         """
         db.create_table("test3", [
             ('SELECT', models.BooleanField(default=False)),
-            ('eggs', models.IntegerField()),
+            ('eggs', models.IntegerField(unique=True)),
         ])
+        db.execute_deferred_sql()
         db.start_transaction()
         # Add an index on that column
         db.create_index("test3", ["SELECT"])
         # Delete them both
         db.delete_index("test3", ["SELECT"])
         db.delete_index("test3", ["SELECT", "eggs"])
+        # Delete the unique index
+        db.delete_index("test3", ["eggs"])
         db.rollback_transaction()
         db.delete_table("test3")