charettes avatar charettes committed 1ec9bcf

Added a test

Comments (0)

Files changed (2)


     def _find_foreign_constraints(self, table_name, column_name=None):
         constraints = self._constraints_affecting_columns(
                             table_name, [column_name], "FOREIGN KEY")
         primary_key_columns = self._find_primary_key_columns(table_name)
         if len(primary_key_columns) > 1:
             # Composite primary keys cannot be referenced by a foreign key
             return list(constraints)


 from south.db import db, generic
 from django.db import connection, models
+from import skipUnless
 # Create a list of error classes from the various database libraries
 errors = []
             ('UNIQUE', models.ForeignKey(Test)),
+    @skipUnless(db.supports_foreign_keys, 'Foreign keys can only be deleted on '
+                                          'engines that support them.')
+    def test_recursive_foreign_key_delete(self):
+        """
+        Test that recursive foreign keys are deleted correctly (see #1065)
+        """
+        Test = db.mock_model(model_name='Test', db_table='test_rec_fk_del',
+                             db_tablespace='', pk_field_name='id',
+                             pk_field_type=models.AutoField, pk_field_args=[])
+        db.create_table('test_rec_fk_del', [
+            ('id', models.AutoField(primary_key=True, auto_created=True)),
+            ('fk', models.ForeignKey(Test)),
+        ])
+        db.execute_deferred_sql()
+        db.delete_foreign_key('test_rec_fk_del', 'fk_id')
     def test_rename(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.