diff --git a/tests/_utils/setup.sql b/tests/_utils/setup.sql index 12ba2584a462..76322bf0f407 100644 --- a/tests/_utils/setup.sql +++ b/tests/_utils/setup.sql @@ -429,3 +429,13 @@ CREATE TABLE `contenttypes_tests_modelwithm2mtosite_site` ( KEY (`modelwithm2mtosite_id`), KEY (`site_id`) ); + +--test_runner +CREATE TABLE `test_runner_person_friend` ( + `from_person_id` BIGINT NOT NULL, + `to_person_id` BIGINT NOT NULL, + SHARD KEY (`from_person_id`), + UNIQUE KEY (`from_person_id`, `to_person_id`), + KEY (`from_person_id`), + KEY (`to_person_id`) +); diff --git a/tests/test_runner/models.py b/tests/test_runner/models.py index 80bf8dd8c769..313c07d3a23d 100644 --- a/tests/test_runner/models.py +++ b/tests/test_runner/models.py @@ -4,7 +4,19 @@ class Person(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20) - friends = models.ManyToManyField("self") + friends = models.ManyToManyField("self", through="PersonFriend") + +class PersonFriend(models.Model): + from_person = models.ForeignKey( + Person, on_delete=models.CASCADE, related_name="from_person" + ) + to_person = models.ForeignKey( + Person, on_delete=models.CASCADE, related_name="to_person" + ) + + class Meta: + unique_together = (('from_person', 'to_person'),) + db_table = "test_runner_person_friend" # A set of models that use a non-abstract inherited 'through' model.