python - Django 不一致迁移历史
问题描述
我正在尝试设置一个 Django 项目,但遇到以下错误:
WARNINGS:
?: (rest_framework.W001) You have specified a default PAGE_SIZE pagination rest_framework setting,without specifying also a DEFAULT_PAGINATION_CLASS.
HINT: The default for DEFAULT_PAGINATION_CLASS is None. In previous versions this was PageNumberPagination. If you wish to define PAGE_SIZE globally whilst defining pagination_class on a per-view basis you may silence this check.
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 82, in handle
executor.loader.check_consistent_history(connection)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/db/migrations/loader.py", line 291, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration events.0001_initial is applied before its dependency commons.0001_initial on database 'default'.
make: *** [migrate] Error 1
我在虚拟环境中运行它,并且有一个用于运行 postgres 数据库的 docker-compose 容器。不知道如何开始调试它或它为什么会发生。任何帮助,将不胜感激
解决方案
在项目内的迁移文件夹中执行以下步骤:
删除pycache和0001_initial 文件。
从根目录中删除 db.sqlite3(注意所有数据都会消失)。在终端运行:
python manage.py makemigrations
python manage.py migrate
注意:不要忘记备份您的数据。
更多详情,您可以点击链接
推荐阅读
- css - 在 React 代码中插入 CSS 行
- perl - 调用定义为变量的子程序
- java - java.lang.AssertionError:未设置内容类型
- python - 使用 ImageDataGenerator 时如何使用 to_categorical
- c# - 当我通过元组列表循环时,它显示索引超出范围错误
- r - 何时终止正在运行的脚本 R
- python - 从 Google Analytics 导出特定细分的受众概览数据
- dart - Dart - 基于椭圆曲线的密钥生成 25519
- amazon-advertising-api - 有没有办法使用亚马逊广告 API 获得广告系列的总支出和总销售额?
- javascript - 根据行和列在onclick中获取值