我正在尝试为表单集编写单元测试,但是在尝试实例化它时遇到以下错误。
错误:
Traceback (most recent call last):
File "/home/jwelborn/Documents/projects/Bingo/bingo/cards/tests/test_forms.py", line 218, in test_formset_accepts_valid_data
self.assertTrue(formset.is_valid())
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/forms/formsets.py", line 321, in is_valid
self.errors
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/forms/formsets.py", line 295, in errors
self.full_clean()
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/forms/formsets.py", line 343, in full_clean
for i in range(0, self.total_form_count()):
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/forms/formsets.py", line 116, in total_form_count
return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max)
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/jwelborn/Documents/projects/Bingo/bingoenv/lib/python3.6/site-packages/django/forms/formsets.py", line 98, in management_form
code='missing_management_form',
django.core.exceptions.ValidationError: ['ManagementForm data is missing or has been tampered with']
Run Code Online (Sandbox Code Playgroud)
此错误表明我缺少ManagmentForm数据,但我将其包含在要传递给表单的字典中。我检查了不同的拼写并更改了最小和最大数字,无济于事。
forms.py:
class BingoSquareForm(ModelForm): …Run Code Online (Sandbox Code Playgroud)