Commits

Maximiliano Robaina  committed 74993d6

Avoid double index creation (#1317)

  • Participants
  • Parent commits bfdb6fe

Comments (0)

Files changed (3)

File south/db/firebird.py

             for stmt in field.post_create_sql(no_style(), table_name):
                 self.add_deferred_sql(stmt)
 
-        # In 1.2 and above, you have to ask the DatabaseCreation stuff for it.
-        # This also creates normal indexes in 1.1.
-        if hasattr(self._get_connection().creation, "sql_indexes_for_field"):
-            # Make a fake model to pass in, with only db_table
-            model = self.mock_model("FakeModelForGISCreation", table_name)
-            for stmt in self._get_connection().creation.sql_indexes_for_field(model, field, no_style()):
-                self.add_deferred_sql(stmt)
+        # Avoid double index creation (#1317)
+        # Firebird creates an index implicity for each foreign key field 
+        # sql_indexes_for_field tries to create an index for that field too
+        if not field.rel:
+            # In 1.2 and above, you have to ask the DatabaseCreation stuff for it.
+            # This also creates normal indexes in 1.1.
+            if hasattr(self._get_connection().creation, "sql_indexes_for_field"):
+                # Make a fake model to pass in, with only db_table
+                model = self.mock_model("FakeModelForGISCreation", table_name)
+                for stmt in self._get_connection().creation.sql_indexes_for_field(model, field, no_style()):
+                    self.add_deferred_sql(stmt)
 
         if sql:
             return sql % sqlparams

File south/tests/__init__.py

 if not skiptest:
     from south.tests.db import *
     from south.tests.db_mysql import *
+    from south.tests.db_firebird import *
     from south.tests.logic import *
     from south.tests.autodetection import *
     from south.tests.logger import *

File south/tests/db_firebird.py

+from django.db import models
+
+from south.db import db
+from south.tests import unittest, skipIf, skipUnless
+
+
+class FirebirdTests(unittest.TestCase):
+
+    """
+    Tests firebird related issues
+    """
+
+    def setUp(self):
+        print('=' * 80)
+        print('Begin Firebird test')
+
+    def tearDown(self):
+        print('End Firebird test')
+        print('=' * 80)
+
+    def test_firebird_double_index_creation_1317(self):
+        """
+        Tests foreign key creation, especially uppercase (see #61)
+        """
+        Test = db.mock_model(model_name='Test',
+            db_table='test5a',
+            db_tablespace='',
+            pk_field_name='ID',
+            pk_field_type=models.AutoField,
+            pk_field_args=[]
+        )
+        db.create_table("test5a", [('ID', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True))])
+        db.create_table("test5b", [
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('UNIQUE', models.ForeignKey(Test)),
+        ])
+        db.execute_deferred_sql()
+