Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地运行第四步迁移数据库时报错,在项目根目录下创建database文件夹后解决 #2

Open
ode126 opened this issue Nov 1, 2019 · 1 comment

Comments

@ode126
Copy link

ode126 commented Nov 1, 2019

运行环境: Ubuntu18.04,按照README.md 中的步骤,尝试在本地运行,在第四步迁移数据库,执行
pipenv run python manage.py migrate
命令时发生报错,错误信息是:
django.db.utils.OperationalError: unable to open database file
并且根目录下并没有像以往一样生成db.sqlite3文件,于是去查看
HelloDjango-blog-tutorial/blogproject/settings文件夹下的common.py文件,发现DATABASES设置如下:

DATABASES = {
    'default': {
        'ENGINE' 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'database', 'db.sqlite3'),
    } 

根据django官方文档:

NAME¶
默认值:(''空字符串)

要使用的数据库的名称。对于SQLite,它是数据库文件的完整路径。指定路径时,即使在Windows(例如C:/homes/user/mysite/sqlite3.db)上,也始终使用正斜杠。

'NAME'指定了db.sqlite3文件的完整路径,但是克隆下来的项目根目录中并没有database这个文件夹,因此导致报错unable to open database file,在项目根目录下手动新建database文件夹后,问题解决。

@ode126 ode126 closed this as completed Nov 8, 2019
@suzhi82
Copy link

suzhi82 commented Dec 26, 2019

今天也遇到了这个问题,解决后才看到这个帖子。

@ode126 ode126 reopened this Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants