A
A
Arsen Abakarov2017-02-12 11:55:19
Python
Arsen Abakarov, 2017-02-12 11:55:19

Sqlite, sqlalchemy, empty db created?

Good afternoon.
I am writing a small stray for routine
The project uses sqlalchemy==1.1.5
I need to open an existing database and read data from there, there are no problems with this
I would like to take into account the situation when the user made a mistake in the path to the database file
I do this:

if os.path.exists(settings.DB_FILE):
    BaseModel.metadata.create_all(engine)

If for some reason the file was not found, then the schema will not be created, but I have a program with GUI on PyQt, there is a log area, in the program itself I catch exceptions and send them to this log
. So, when I try to make a request from gui logs that the path is incorrect, but an empty database file is created, when the program is restarted, the existence check passes, a schema is created in this file and as a result the program works with an empty database
How to make a request to a non-existent database not create an empty file, I don't want to crash the program on startup.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
1011, 2017-02-12
@1011

How to make a query to a non-existent database not create an empty file

Perhaps look for the place where this file is created? It turns out that QT starts this process? Can you start debugging step by step in your IDE?
when trying to make a request from the GUI, it logs that the path is incorrect, but an empty database file is created,
I didn’t understand a little, that is, here the program does not intercept the error and collapses? But does it work the way it should?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question