我是Django的新手,请多多包涵。
我在做python manage.py migrate
时遇到此错误
Applying mailing.0002_auto_20190221_1932...Traceback (most recent call last):
File "findoor_backend/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
fake_initial=fake_initial,
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 112, in apply
operation.state_forwards(self.app_label, project_state)
File "/home/andykw/cloned_projects/findoor-backend/.venv/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 196, in state_forwards
state.models[app_label, self.model_name_lower].fields
KeyError: ('mailing', 'questionanswer')
阅读此answer,似乎我在某处缺少一列,但看不到哪里。我不确定是否必须在我的视图中添加它。
这是我的模型
class QuestionAnswer(models.Model):
"""Mail for answer to a question"""
if site_lang == 'fr':
default_subject = answered_subject_fr
default_message = answered_message_fr
elif site_lang == 'pl':
default_subject = answered_subject_pl
default_message = answered_message_pl
else:
default_subject = answered_subject_en
default_message = answered_message_en
subject = models.CharField(max_length=100, unique=True,
verbose_name=_("mail subject"), default=default_subject)
contents = models.TextField(verbose_name=_("mail contents"),
help_text="Keywords: {{site_name}}, {{question_first_name}}, \
{{question_last_name}}, {{question_message}}, {{answer}},\
{{expert_first_name}}, {{expert_last_name}}", default=default_message)
active = models.BooleanField(default=False)
这是我的视图
# MAIL FOR QuestionAnswer
# French version
answered_subject_fr = "{{site_name}} - Vous avez reçu une réponse"
answered_message_fr = """Bonjour,
{{expert_first_name}} {{expert_last_name}} a répondu à votre question sur {{site_name}} . Voici sa réponse:
{{answer}}
Pour rappel, votre question était:
{{question_message}}
Cordialement"""
# English version
answered_subject_en = "{{site_name}} - You got an answer"
answered_message_en = """Hello,
{{expert_first_name}} {{expert_last_name}} answered your question on {{site_name}} . Here is the reply :
{{answer}}
As a reminder, your question was :
{{question_message}}
Regards, """
# Polish version
answered_subject_pl = "{{site_name}} - Powiadomienie o odpowiedzi"
answered_message_pl = """Dzień dobry {{expert_first_name}},
Oto odpowiedź na pytanie, które zadałeś na stronie internetowej {{site_name}} :
{{answer}}
Dla przypomnienia, pytanie brzmiało:
{{question_message}}
Aby kontynuować dyskusję z ekspertem, zaloguj się do swojego konta lub utwórz konto w odpowiedniej sekcji.
Pozdrawiamy,"""
这是我的表格
@admin.register(QuestionAnswer)
class QuestionAnswerAdmin(CompareVersionAdmin):
list_display = LIST_DISP
fieldsets = FIELDSETS
我正在添加导致问题的迁移脚本
# Generated by Django 2.0.3 on 2019-02-21 18:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mailing', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='questionanswer',
name='contents',
field=models.TextField(default='Dear {{question_first_name}},\n\nHere is the answer to the question you asked on the website {{site_name}}:\n{{answer}}\n\nAs a reminder, the question was: {{question_message}}\n\nTo continue the discussion with this expert, log in to your space or create an account in the appropriate section.\n\n\nSee you soon,', help_text='Keywords: {{site_name}}, {{question_first_name}}, {{question_last_name}}, {{question_message}}, {{answer}}, {{expert_first_name}}, {{expert_last_name}}', verbose_name='mail contents'),
),
migrations.AlterField(
model_name='questionanswer',
name='subject',
field=models.CharField(default='{{site_name}} - Reply Notification', max_length=100, unique=True, verbose_name='mail subject'),
),
]
谢谢