Skip to content

Commit b02b070

Browse files
committed
fix news migration?
1 parent 27d20b5 commit b02b070

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

news/migrations/0007_project_news_2_news_news.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# Generated by Django 4.2.3 on 2023-07-20 18:34
2+
import os
23

34
from django.db import migrations
45
from django.db.migrations import RunPython
56

67

78
def project_news_to_news_news(apps, schema_editor):
8-
# add ProjectNews model to news app via schema_editor
99
ProjectNews = apps.get_model("projects.ProjectNews")
1010
News = apps.get_model("news", "News")
1111
ContentType = apps.get_model("contenttypes", "ContentType")
12-
project_content_type = ContentType.objects.get(
13-
app_label="projects", model="project"
14-
)
12+
content_type_count = ContentType.objects.all().count()
13+
if content_type_count == 0:
14+
return
15+
1516
project_news_content_type = ContentType.objects.get(
1617
app_label="projects", model="projectnews"
1718
)
19+
project_content_type = ContentType.objects.get(
20+
app_label="projects", model="project"
21+
)
22+
1823
news_content_type = ContentType.objects.get(app_label="news", model="news")
1924
Like = apps.get_model("core", "Like")
2025
View = apps.get_model("core", "View")
@@ -50,7 +55,9 @@ class Migration(migrations.Migration):
5055

5156
dependencies = [
5257
("news", "0006_alter_news_options_remove_news_cover_url_and_more"),
53-
("projects", "0013_projectnews")
58+
("projects", "0013_projectnews"),
59+
("projects", "0001_initial"),
60+
("projects", "0002_initial"),
5461
]
5562

5663
operations = [

0 commit comments

Comments
 (0)