#Django官方教程
#报错:No changes detected in app 'polls'
原因分析:
当我运行:python manage.py migrate
提示我:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
Your models in app(s): 'polls' have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
操作步骤:
- 在迁移之前没有填正确填写并保存models.py(关键)
- 再执行命令:python manage.py makemigrations polls
改变模型需要这三步:
- 编辑
models.py
文件,改变模型。 - 运行 python manage.py makemigrations 为模型的改变生成迁移文件。
- 运行 python manage.py migrate 来应用数据库迁移。
参考文献
Django Software Foundation. (2024). Django文档. Retrieved June 4, 2024, from Django 文档 | Django 文档 | Django