【问题标题】:I'm getting this error when trying to run a django aplication: django.db.utils.OperationalError: unsupported file format尝试运行 django 应用程序时出现此错误:django.db.utils.OperationalError: unsupported file format
【发布时间】:2021-09-17 11:35:38
【问题描述】:

程序在几分钟前运行良好,在我的帖子 URL 中添加 SlugField我觉得它与错误无关,这是当我在终端中运行 Python3 manage.py runserver 时得到什么。

System check identified some issues:

WARNINGS:
base.Post.tags: (fields.W340) null has no effect on ManyToManyField.

System check identified 1 issue (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 394, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: unsupported file format

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/peace/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/peace/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check_migrations()
  File "/home/peace/.local/lib/python3.6/site-packages/django/core/management/base.py", line 458, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations
    if self.has_table():
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
    return get_names(cursor)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/introspection.py", line 73, in get_table_list
    ORDER BY name""")
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql)
  File "/home/peace/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 394, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: unsupported file format

我只是不确定是否应该更改某些内容,因为存在不受支持的文件格式。只是不确定它正在谈论的文件:( 是错误还是我做错了什么?

【问题讨论】:

  • 几乎看起来你的 sqlite3 数据库文件是 FUBAR。你试过把它移到一边重新开始吗?
  • 原来如此:) 谢谢

标签: python django compiler-errors


【解决方案1】:

我建议删除您的 sqlite3 和迁移文件夹,然后运行以下命令:

python3 manage.py makemigrations <app>
python3 manage.py migrate
python3 manage.py runserver

删除迁移可以参考这个链接:https://riptutorial.com/django/example/29416/resetting-django-migration--deleting-existing-database-and-migrating-as-fresh

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2022-12-20
  • 1970-01-01
  • 1970-01-01
  • 2018-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
相关资源
最近更新 更多