【发布时间】:2019-08-02 13:26:17
【问题描述】:
我有一个半大型软件。有一次,我将 table2 包含在该项目中并开始使用它。在 filter.py 文件中,我包含了一些基本的模型过滤。现在,如果我删除我的数据库并尝试运行新的迁移,我会收到错误,该表不可用。我构建了一个 try catch 并且它正在工作,因为它不运行在迁移之前剪切的代码。
class PracticephaseProjectFilter(django_filters.FilterSet):
omni = django_filters.CharFilter(method=omni_search, label="Suche")
practice_phase = django_filters.ModelChoiceFilter(queryset=PracticePhase.objects.filter(pk__in=get_pp_for_specialpermit()))
class Meta:
model = PracticePhaseProject
fields = ['practice_phase']
def __init__(self, *args, **kwargs):
super(PracticephaseProjectFilter, self).__init__(*args, **kwargs)
def get_pp_for_specialpermit():
pp = []
today = date.today()
# check if SS or WS required
if 4 <= today.month <= 9:
# current SS, project will be sought for WS this year
pp_str = [str(today.year)[-2:] + "s", str(today.year - 1)[-2:] + "w"]
# we are in WS, check correct year for SS
elif today.month > 9:
pp_str = [str(today.year)[-2:] + "w", str(today.year)[-2:] + "s"]
# we are allready in the year of next SS
else:
pp_str = [str(today.year - 1)[-2:] + "s", str(today.year - 1)[-2:] + "w"]
try:
for _pp in PracticePhase.objects.filter(semester__name__in=pp_str):
pp.append(_pp.pk)
except:
pass
return pp
现在,如果我删除 for 循环周围的 try catch,我将无法运行迁移,因为我遇到了没有表实践阶段的数据库错误。但是在迁移之前永远不应该调用该文件。
【问题讨论】:
标签: python django django-migrations django-tables2