diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index fcc6ab7..44a5e58 100644
a
|
b
|
class BaseDatabaseCreation(object):
|
137 | 137 | """ |
138 | 138 | from django.db.backends.util import truncate_name |
139 | 139 | |
140 | | if not model._meta.managed or model._meta.proxy: |
| 140 | if not model._meta.managed: |
141 | 141 | return [] |
142 | 142 | qn = self.connection.ops.quote_name |
143 | 143 | final_output = [] |
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py
index af4952d..f54f1f7 100644
a
|
b
|
class Reporter(models.Model):
|
63 | 63 | return "%s %s" % (self.first_name, self.last_name) |
64 | 64 | |
65 | 65 | |
| 66 | class ReporterProxy(Reporter): |
| 67 | class Meta: |
| 68 | proxy = True |
| 69 | |
| 70 | |
66 | 71 | class Article(models.Model): |
67 | 72 | headline = models.CharField(max_length=100) |
68 | 73 | pub_date = models.DateField() |
69 | 74 | reporter = models.ForeignKey(Reporter) |
| 75 | reporter_proxy = models.ForeignKey(ReporterProxy, null=True, |
| 76 | related_name='reporter_proxy') |
70 | 77 | |
71 | 78 | def __unicode__(self): |
72 | 79 | return self.headline |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index a6425c5..fcdc581 100644
a
|
b
|
class FkConstraintsTests(TransactionTestCase):
|
438 | 438 | Try to create a model instance that violates a FK constraint. If it |
439 | 439 | fails it should fail with IntegrityError. |
440 | 440 | """ |
441 | | a = models.Article(headline="This is a test", pub_date=datetime.datetime(2005, 7, 27), reporter_id=30) |
| 441 | a1 = models.Article(headline="This is a test", pub_date=datetime.datetime(2005, 7, 27), reporter_id=30) |
442 | 442 | try: |
443 | | a.save() |
| 443 | a1.save() |
444 | 444 | except IntegrityError: |
445 | | return |
446 | | self.skipTest("This backend does not support integrity checks.") |
| 445 | pass |
| 446 | else: |
| 447 | self.skipTest("This backend does not support integrity checks.") |
| 448 | # Now that we know this backend supports integrity checks we make sure |
| 449 | # constraints are also enforced for proxy models. Refs #17519 |
| 450 | a2 = models.Article(headline='This is another test', reporter=self.r, |
| 451 | pub_date=datetime.datetime(2012, 8, 3), |
| 452 | reporter_proxy_id=30) |
| 453 | self.assertRaises(IntegrityError, a2.save) |
447 | 454 | |
448 | 455 | def test_integrity_checks_on_update(self): |
449 | 456 | """ |
… |
… |
class FkConstraintsTests(TransactionTestCase):
|
452 | 459 | """ |
453 | 460 | # Create an Article. |
454 | 461 | models.Article.objects.create(headline="Test article", pub_date=datetime.datetime(2010, 9, 4), reporter=self.r) |
455 | | # Retrive it from the DB |
456 | | a = models.Article.objects.get(headline="Test article") |
457 | | a.reporter_id = 30 |
| 462 | # Retrieve it from the DB |
| 463 | a1 = models.Article.objects.get(headline="Test article") |
| 464 | a1.reporter_id = 30 |
458 | 465 | try: |
459 | | a.save() |
| 466 | a1.save() |
460 | 467 | except IntegrityError: |
461 | | return |
462 | | self.skipTest("This backend does not support integrity checks.") |
| 468 | pass |
| 469 | else: |
| 470 | self.skipTest("This backend does not support integrity checks.") |
| 471 | # Now that we know this backend supports integrity checks we make sure |
| 472 | # constraints are also enforced for proxy models. Refs #17519 |
| 473 | # Create another article |
| 474 | r_proxy = models.ReporterProxy.objects.get(pk=self.r.pk) |
| 475 | models.Article.objects.create(headline='Another article', |
| 476 | pub_date=datetime.datetime(1988, 5, 15), |
| 477 | reporter=self.r, reporter_proxy=r_proxy) |
| 478 | # Retreive the second article from the DB |
| 479 | a2 = models.Article.objects.get(headline='Another article') |
| 480 | a2.reporter_proxy_id = 30 |
| 481 | self.assertRaises(IntegrityError, a2.save) |
463 | 482 | |
464 | 483 | def test_disable_constraint_checks_manually(self): |
465 | 484 | """ |