【问题标题】:Django Polls Tutorial No changes detected in app pollsDjango Polls 教程在应用程序投票中未检测到更改
【发布时间】:2014-09-18 02:51:50
【问题描述】:

我正在阅读 Django Polls 教程,我正在尝试命令“python manage.py makemigrations polls”,但我不断收到消息“在应用程序'polls'中没有检测到更改”

我不明白我做错了什么,或者我该如何做不同的事情,或者这个消息的含义。

为清楚起见进行编辑:

我希望有点像教程上的打印输出:

Migrations for 'polls':
  0001_initial.py:
    - Create model Question
    - Create model Choice

然后在本教程的稍后部分,当它要求我键入命令 python manage.py sqlmigrate polls 0001 时,我会得到某种打印输出,如所示(相当长)。我正在学习https://docs.djangoproject.com/en/1.7/intro/tutorial01/的教程

相反,我得到了

CommandError: Cannot find a migration matching 'polls' form app '0001'. Is it in INSTALLED_APPS?

【问题讨论】:

  • 运行该命令有什么期望?如果你之前运行过这个,可能是因为你的模型实际上没有变化。
  • 抱歉,我会编辑更多信息。
  • 感谢您的更新,这将使我们更好地了解如何进行故障排除。在您的“settings.py”文件中,“投票”是否列在“INSTALLED_APPS”中?
  • 您在 settings.py 中仅使用“民意调查”就正确了。嗯,这真的很奇怪。听起来迁移可能已经发生了。你能运行'python manage.py sqlmigrate polls 0001'看看SQL出现了什么吗?

标签: python django django-migrations


【解决方案1】:

问题最终是在迁移之前未填写 models.py。它应该是这样的。

models.py 文件:

from django.db import models 

class Question(models.Model): 
    question_text = models.CharField(max_length=200) 
    pub_date = models.DateTimeField('date published') 


class Choice(models.Model): 
    question = models.ForeignKey(Question) 
    choice_text = models.CharField(max_length=200) 
    votes = models.IntegerField(default=0)

还要确保“polls”列在“settings.py”文件的“INSTALLED_APPS”中。

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,只是发现 VSCode 没有处于 AutoSave 模式,这是 VSCode 的新系统/安装。如果正确遵循本教程,唯一的失败实例应该是在运行迁移之前直接在“polls”中的 models.py 没有正确保存。

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2014-02-01
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      相关资源
      最近更新 更多