diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
index 15a3b49..8d8ae3e 100644
a
|
b
|
|
1 | 1 | from django.apps.registry import Apps |
2 | 2 | from django.db import models |
| 3 | from django.utils.encoding import python_2_unicode_compatible |
3 | 4 | from django.utils.timezone import now |
4 | 5 | |
5 | 6 | |
… |
… |
class MigrationRecorder(object):
|
16 | 17 | a row in the table always means a migration is applied. |
17 | 18 | """ |
18 | 19 | |
| 20 | @python_2_unicode_compatible |
19 | 21 | class Migration(models.Model): |
20 | 22 | app = models.CharField(max_length=255) |
21 | 23 | name = models.CharField(max_length=255) |
… |
… |
class MigrationRecorder(object):
|
26 | 28 | app_label = "migrations" |
27 | 29 | db_table = "django_migrations" |
28 | 30 | |
| 31 | def __str__(self): |
| 32 | return "Migration %s for %s" % (self.name, self.app) |
| 33 | |
29 | 34 | def __init__(self, connection): |
30 | 35 | self.connection = connection |
31 | 36 | |
… |
… |
class MigrationRecorder(object):
|
46 | 51 | Returns a set of (app, name) of applied migrations. |
47 | 52 | """ |
48 | 53 | 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")) |
50 | 55 | |
51 | 56 | def record_applied(self, app, name): |
52 | 57 | """ |
53 | 58 | Records that a migration was applied. |
54 | 59 | """ |
55 | 60 | 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) |
57 | 62 | |
58 | 63 | def record_unapplied(self, app, name): |
59 | 64 | """ |
60 | 65 | Records that a migration was unapplied. |
61 | 66 | """ |
62 | 67 | 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() |
64 | 69 | |
65 | | @classmethod |
66 | | def flush(cls): |
| 70 | def flush(self): |
67 | 71 | """ |
68 | 72 | Deletes all migration records. Useful if you're testing migrations. |
69 | 73 | """ |
70 | | cls.Migration.objects.all().delete() |
| 74 | self.Migration.objects.using(self.connection.alias).all().delete() |
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index f661a03..0e9b9c2 100644
a
|
b
|
|
1 | 1 | from unittest import skipIf |
2 | 2 | |
3 | 3 | from django.test import TestCase, override_settings |
4 | | from django.db import connection |
| 4 | from django.db import connection, connections |
5 | 5 | from django.db.migrations.loader import MigrationLoader, AmbiguityError |
6 | 6 | from django.db.migrations.recorder import MigrationRecorder |
7 | 7 | from django.utils import six |
… |
… |
class RecorderTests(TestCase):
|
26 | 26 | recorder.applied_migrations(), |
27 | 27 | set([("myapp", "0432_ponies")]), |
28 | 28 | ) |
| 29 | # That should not affect records of another database |
| 30 | recorder_other = MigrationRecorder(connections['other']) |
| 31 | self.assertEqual( |
| 32 | recorder_other.applied_migrations(), |
| 33 | set(), |
| 34 | ) |
29 | 35 | recorder.record_unapplied("myapp", "0432_ponies") |
30 | 36 | self.assertEqual( |
31 | 37 | recorder.applied_migrations(), |