我的应用程序中有以下模型类,名为" team_rooster
"
class Spieler(StructBlock):
nummer = IntegerBlock(required=True)
position = ChoiceBlock(choices=[
('th', 'TH'),
], icon='cup')
class TeamRooster(Page):
team_name = models.CharField(max_length=100, default="")
spieler = StreamField([
('spieler', CardsBlock(Spieler(), icon="user")),
], default='', blank=True)
content_panels = [
FieldPanel('team_name', classname="col12"),
StreamFieldPanel('spieler'),
]
并在views.py
from django.shortcuts import render
from .models import TeamRooster
# Create your views here.
def teams(request):
teams = TeamRooster.objects.all()
return render(request, 'team_rooster.html', { 'teams': teams})
并加上template
{% extends 'base.html' %}
{% load staticfiles %}
{% load wagtailcore_tags %}
{% block content %}
<div class="container">
{% for team in teams %}
<div class="row">
<table border="2" width="100%">
<tbody>
<tr>
<th colspan="5">{{team.team_name}}</th>
</tr>
<tr>
<td>{{team.spieler.nummer}}</td>
<td>{{team.spieler.position}}</td>
</tr>
</tbody>
</table>
</div>
{% endfor %}
</div>
{% endblock %}
当我进行迁移时,出现错误:
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, home, sessions, taggit, team_rooster, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, wagtailusers
Running migrations:
No migrations to apply.
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\django\apps\config.py", line 169, in get_model
return self.models[model_name.lower()]
KeyError: 'spieler'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python36\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python36\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 186, in handle
changes = autodetector.changes(graph=executor.loader.graph)
File "C:\Python36\lib\site-packages\django\db\migrations\autodetector.py", line 47, in changes
changes = self._detect_changes(convert_apps, graph)
File "C:\Python36\lib\site-packages\django\db\migrations\autodetector.py", line 189, in _detect_changes
self.generate_altered_fields()
File "C:\Python36\lib\site-packages\django\db\migrations\autodetector.py", line 911, in generate_altered_fields
if old_field_dec != new_field_dec:
File "C:\Python36\lib\site-packages\wagtail\wagtailcore\blocks\base.py", line 402, in __eq__
return (self.name == other.name) and (self.deconstruct() == other.deconstruct())
File "C:\Python36\lib\site-packages\wagtailmodelchooser\blocks.py", line 41, in deconstruct
kwargs['target_model'] = self.target_model._meta.label_lower
File "C:\Python36\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python36\lib\site-packages\wagtailmodelchooser\blocks.py", line 24, in target_model
return resolve_model_string(self._target_model)
File "C:\Python36\lib\site-packages\wagtail\wagtailcore\utils.py", line 45, in resolve_model_string
return apps.get_model(app_label, model_name)
File "C:\Python36\lib\site-packages\django\apps\registry.py", line 205, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "C:\Python36\lib\site-packages\django\apps\config.py", line 172, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'team_rooster' doesn't have a 'spieler' model.
在注释掉文本&#34; spieler
&#34;的部分代码之前,我尝试进行迁移。存在,但我仍有错误。
答案 0 :(得分:0)
删除之前使用./manage.py makemigrations
创建的迁移文件,然后重新运行./manage.py makemigrations
请参阅评论