Skip to content

Commit

Permalink
Now without foreign key checks during fixture loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Sep 29, 2010
1 parent 38b2d5f commit ce0e964
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test_utils/runner.py
@@ -1,12 +1,33 @@
import os

from django.db import connections
from django.core.management.commands.loaddata import Command
from django.db import connections, DEFAULT_DB_ALIAS
from django.db.backends.creation import TEST_DATABASE_PREFIX
from django.db.backends.mysql import creation as mysql

import django_nose


# Monkey-patch loaddata to ignore foreign key checks.
_old_handle = Command.handle
def _new_handle(self, *fixture_labels, **options):
using = options.get('database', DEFAULT_DB_ALIAS)
commit = options.get('commit', True)
connection = connections[using]

cursor = connection.cursor()
cursor.execute('SET foreign_key_checks = 0')

_old_handle(self, *fixture_labels, **options)

cursor = connection.cursor()
cursor.execute('SET foreign_key_checks = 1')

if commit:
connection.close()
Command.handle = _new_handle


# XXX: hard-coded to mysql.
class SkipDatabaseCreation(mysql.DatabaseCreation):

Expand Down

0 comments on commit ce0e964

Please sign in to comment.