search

Home  >  Q&A  >  body text

python - flask encountered a sqlite path problem when using sqlalchemy under windows. It always automatically adds a c:// in front.

I have been learning flask recently and encountered problems when using sqlalchemy. I am using win10 system and the configuration file is as follows:

class DevelopmentConfig(Config):
    DEBUG = True
    DATABASE_URI = 'sqlite:////F:/code/python/fishkeeping/fishkeeping/fish.db'
    USERNAME = 'admin'
    PASSWORD = 'a00123456'
    SECRET_KEY = '11f0394a7e0c-4585-af6b-5b4efcf6fd8f'

After that, an exception occurred that the database could not be opened, and it was found that the path was modified by the program to

'C:\F:\code\python\fishkeeping\fishkeeping\fish.db'

After trying several times, I found that no matter what is followed by sqlite:////, a C:\\ will be added in front, which is very strange. Please solve it.

迷茫迷茫2738 days ago752

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-27 17:41:23

    means that your sqlite is followed by 3 slashes instead of 4.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:41:23

    Official documents explain it
    engine = create_engine('sqlite:///C:pathtofoo.db') # Windowsengine = create_engine('sqlite:///C:pathtofoo.db') # Windows
    engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string
    engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string

    reply
    0
  • Cancelreply