正在进入ing...

Django在使用Docker部署收集静态文件时报错

发布时间:2021-04-30 浏览量: 35 文章分类: python

最近换了新版的python然后在按照之前日常打包docker的时候都很正常,但是测试环境突然跑不起来了。 只要一运行就报错了。

Traceback (most recent call last):
  File "/home/django_web/manage.py", line 22, in <module>
    main()
  File "/home/django_web/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 341, in run_from_argv
    connections.close_all()
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 230, in close_all
    connection.close()
  File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 261, in close
    if not self.is_in_memory_db():
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 380, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/creation.py", line 12, in is_in_memory_db
    return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'PosixPath' is not iterable

开始一直以为是哪里有问题,然后进入到容器内部的时候,手动执行命令,发现还是报错。看到最终错误提示是找不到数据库名,在去翻看一些资料的时候找到了解决方法。 主要错误的原因还是由于我们使用的是Django自带的sqlite数据库。如果你还是想这样使用的话。只要按照下面这样既可。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': str(BASE_DIR / 'db.sqlite3'),
    }
}