Skip to content

Solution for Error of flask db in Windows #9

Open

Description

@TianshuoQi

在Windows系统中执行flask db相关操作时,由于"CrackSQL\backend\app_factory.py" 146行db_url当前格式与Windows环境不匹配,需要做如下修改:
修改前:
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite://{db_uri}'
修改后:
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{db_path.as_posix()}"

Activity

  1. changed the title [-]Error of flask db in Windows[/-] [+]Error of `flask db` in Windows Solution[/+] on May 22, 2025
  2. changed the title [-]Error of `flask db` in Windows Solution[/-] [+]Solution for Error of `flask db` in Windows[/+] on May 23, 2025
  3. TianshuoQi commented on May 23, 2025

    @TianshuoQi
    Author

    如果在WIndows环境中运行flask db相关的指令时遇到了"unable to open database file"的报错,请尝试做上面的修改。导致错误的原因是在Windows环境中路径使用\,在原来的代码中可能构造出非法的URL;而修改后的代码使用as_posix()将其转换成URL-friendly的格式。

  4. code4DB commented on May 24, 2025

    @code4DB
    Collaborator

    Thanks for your solution, CrackSQL is tested over Linux by default :)

  5. illusionarydream commented on Jun 10, 2025

    @illusionarydream

    For me, I tested the CrackSQL on my manjaro linux. Chinese characters exist in my path to the project. as_url() function will REPLACE the Unicode with percenta-code for better compatibility.

    e.g: (since there has no senstive info in my path, I give it directly).
    /home/illusionary/文档/大三/工科创/Final-Proj/dataset/CrackSQL/backend/instance/info.db
    /home/illusionary/%E6%96%87%E6%A1%A3/%E5%A4%A7%E4%B8%89/%E5%B7%A5%E7%A7%91%E5%88%9B/Final-Proj/dataset/CrackSQL/backend/instance/info.db

    However, this will cause "unable to open database file" as well. Use as_posix() will solve this problem because this function DO NOT make this replacement.

  6. code4DB commented on Jun 11, 2025

    @code4DB
    Collaborator

    @illusionarydream Hi! Do you mean the as_posix() function is the correction solution for your problem?

  7. illusionarydream commented on Jun 11, 2025

    @illusionarydream

    It's exactly not the only correction for my problem. Actually, If I DO NOT make the replacement of Chinese character, this problem will not exist as well. So this problem appears when you use a path containing Chinese character, which is a crucial point. However, my Manjaro OS supports Unicode, different OS may have different situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions