【问题标题】:Migration error in django, what error am I running into?django中的迁移错误,我遇到了什么错误?
【发布时间】:2021-07-07 22:08:19
【问题描述】:

我正在尝试使用命令迁移我的更改

python manage.py migrate

我已经运行了命令,

python manage.py makemigrations accounts

成功返回,

Migrations for 'accounts':
  accounts/migrations/0001_initial.py
    - Create model CustomUser

然后在尝试运行python manage.py migrate 时收到此错误...

Traceback (most recent call last):
  File "/home/mycroft/C/news/manage.py", line 22, in <module>
    main()
  File "/home/mycroft/C/news/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 95, in handle
    executor.loader.check_consistent_history(connection)
  File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/db/migrations/loader.py", line 302, in check_consistent_history
    raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.

我对 django 很陌生,似乎无法弄清楚我做错了什么。任何帮助将不胜感激!

【问题讨论】:

    标签: python django django-rest-framework web-applications pipenv


    【解决方案1】:

    也许您对您的 models.py 文件进行了一些更改,而这些更改与初始数据库结构不相符。如果您可以跟踪和撤消最近的更改,它可能会有所帮助,否则您将不得不删除您的数据库,删除您的 account 应用程序的所有迁移文件。然后重复 makemigration、migrate 和 createsuperuser 进程。

    【讨论】:

      猜你喜欢
      • 2020-11-01
      • 1970-01-01
      • 2017-10-13
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      • 2016-02-14
      • 2012-08-06
      相关资源
      最近更新 更多