From 7cfdfba656a365fc83cd6c145976b22cc3482987 Mon Sep 17 00:00:00 2001 From: Pavlo Mishchenko Date: Fri, 16 May 2025 16:51:07 +0300 Subject: [PATCH] change migration --- tests/_utils/setup.sql | 2 +- .../migrations/0002_create_test_models.py | 37 ++++++++++++++++--- tests/db_functions/models.py | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/_utils/setup.sql b/tests/_utils/setup.sql index 8db56428e54c..b3d1aff1eead 100644 --- a/tests/_utils/setup.sql +++ b/tests/_utils/setup.sql @@ -517,7 +517,7 @@ CREATE TABLE `generic_relations_regress_organization_contact` ( ); -- db_functions -CREATE TABLE `db_functions_article_authors` ( +CREATE TABLE `db_functions_article_author` ( `article_id` BIGINT NOT NULL, `author_id` BIGINT NOT NULL, SHARD KEY (`article_id`), diff --git a/tests/db_functions/migrations/0002_create_test_models.py b/tests/db_functions/migrations/0002_create_test_models.py index 37ee93f92f6e..4934ccb6e211 100644 --- a/tests/db_functions/migrations/0002_create_test_models.py +++ b/tests/db_functions/migrations/0002_create_test_models.py @@ -19,12 +19,6 @@ class Migration(migrations.Migration): migrations.CreateModel( name="Article", fields=[ - ( - "authors", - models.ManyToManyField( - "db_functions.Author", related_name="articles" - ), - ), ("title", models.CharField(max_length=50)), ("summary", models.CharField(max_length=200, null=True, blank=True)), ("text", models.TextField()), @@ -34,6 +28,37 @@ class Migration(migrations.Migration): ("views", models.PositiveIntegerField(default=0)), ], ), + migrations.CreateModel( + name="ArticleAuthor", + fields=[ + ( + "article", + models.ForeignKey( + on_delete=models.CASCADE, to="db_functions.article" + ), + ), + ( + "author", + models.ForeignKey( + on_delete=models.CASCADE, to="db_functions.author" + ), + ), + ], + options={ + "managed": False, + "db_table": "db_functions_article_author", + "unique_together": {("article", "author")}, + }, + ), + migrations.AddField( + model_name="article", + name="authors", + field=models.ManyToManyField( + related_name="articles", + through="db_functions.ArticleAuthor", + to="db_functions.author", + ), + ), migrations.CreateModel( name="Fan", fields=[ diff --git a/tests/db_functions/models.py b/tests/db_functions/models.py index 9ec6d00a84f8..7b4336d0aacb 100644 --- a/tests/db_functions/models.py +++ b/tests/db_functions/models.py @@ -28,7 +28,7 @@ class ArticleAuthor(models.Model): class Meta: unique_together = (('article', 'author'),) - db_table = "db_functions_article_authors" + db_table = "db_functions_article_author" class Fan(models.Model):