Ticket #22474: 22474-1.diff

File 22474-1.diff, 2.2 KB (added by Claude Paroz, 11 years ago)

Use the proper database to query for Migrations

  • django/db/migrations/recorder.py

    diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
    index 15a3b49..a0c0404 100644
    a b  
    11from django.apps.registry import Apps
    22from django.db import models
     3from django.utils.encoding import python_2_unicode_compatible
    34from django.utils.timezone import now
    45
    56
    class MigrationRecorder(object):  
    1617    a row in the table always means a migration is applied.
    1718    """
    1819
     20    @python_2_unicode_compatible
    1921    class Migration(models.Model):
    2022        app = models.CharField(max_length=255)
    2123        name = models.CharField(max_length=255)
    class MigrationRecorder(object):  
    2628            app_label = "migrations"
    2729            db_table = "django_migrations"
    2830
     31        def __str__(self):
     32            return "Migration %s for %s" % (self.name, self.app)
     33
    2934    def __init__(self, connection):
    3035        self.connection = connection
    3136
    class MigrationRecorder(object):  
    4651        Returns a set of (app, name) of applied migrations.
    4752        """
    4853        self.ensure_schema()
    49         return set(tuple(x) for x in self.Migration.objects.values_list("app", "name"))
     54        return set(tuple(x) for x in self.Migration.objects.using(self.connection.alias).values_list("app", "name"))
    5055
    5156    def record_applied(self, app, name):
    5257        """
    5358        Records that a migration was applied.
    5459        """
    5560        self.ensure_schema()
    56         self.Migration.objects.create(app=app, name=name)
     61        self.Migration.objects.using(self.connection.alias).create(app=app, name=name)
    5762
    5863    def record_unapplied(self, app, name):
    5964        """
    6065        Records that a migration was unapplied.
    6166        """
    6267        self.ensure_schema()
    63         self.Migration.objects.filter(app=app, name=name).delete()
     68        self.Migration.objects.using(self.connection.alias).filter(app=app, name=name).delete()
    6469
    6570    @classmethod
    6671    def flush(cls):
    6772        """
    6873        Deletes all migration records. Useful if you're testing migrations.
    6974        """
    70         cls.Migration.objects.all().delete()
     75        cls.Migration.objects.using(self.connection.alias).all().delete()
Back to Top