Table 'django_migrations' 在删除数据库后已经存在

Table 'django_migrations' already exists after dropping database

我最近遇到了数据库问题,因为我没有重要数据,所以我决定关闭它。我删除了我的应用程序目录中的迁移文件夹并删除了数据库。但是,现在当我使用 manage.py migrate 重新创建所有内容时,出现以下错误:

  File "../manage.py", line 21, in <module>
    main()
  File "../manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 69, in ensure_schema
    raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1050, "Table 'django_migrations' already exists"))

我在删除数据库并重新创建空数据库后尝试了 运行。我可以 100% 确定现在没有 table。所以我不知道为什么它认为 table 在那里。

解决了我的问题。 MariaDB 在缓存中打开了我的表。我运行两个语句:FLUSH QUERY CACHE;FLUSH TABLES;。我不确定是哪一个成功了,但我可以 运行 迁移,现在一切都恢复正常了!

删除了迁移并重新创建了项目目录和startapp 目录。 然后进行迁移和迁移。工作于 mySQL。