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.
means that your sqlite is followed by 3 slashes instead of 4.
Official documents explain it
engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw stringengine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string