删除数据库后,表“ django_migrations”已存在

时间:2019-11-29 11:04:36

标签: django mariadb django-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%确保目前没有桌子。所以我不知道为什么它认为那张桌子在那里。

2 个答案:

答案 0 :(得分:4)

弄清楚了我的问题。 MariaDB在缓存中打开了我的表。我运行了两个语句:FLUSH QUERY CACHE;FLUSH TABLES;。我不确定是哪一个成功了,但是后来我能够运行迁移,并且现在一切都恢复了!

答案 1 :(得分:0)

删除了迁移,并再次创建了项目目录和startapp目录。 然后进行迁移并迁移。在mySQL上工作。