PyQt5: specifying QSqlTableModel

Colin McPhail colin.mcphail at mac.com
Sat Jun 5 08:47:46 BST 2021


Rich,

> On 4 Jun 2021, at 20:38, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> 
> On Fri, 4 Jun 2021, Colin McPhail wrote:
> 
>> It might be an idea to add some error checking. I put the following just
>> after the self.model.select() line:
>> ...

>> Perhaps you might see some other message that indicates what's going wrong?
> 
> Colin,
> 
> Indeed I do. The last few lines of the log file for your modified file shows
> the problem:
> INFO:root:found database
> DEBUG:root:Defining model/view
> DEBUG:root:model error:  Unable to find table foods_episodes
> DEBUG:root:End of Program
> 
> Yet when I open foods.db with sqlite-3.34.0 the table is present.
> 
> Similarly, when I run my activitytypes.py I get the same error:
> INFO:root:found database
> DEBUG:root:Defining model/view
> DEBUG:root:model error:  Unable to find table activitytypes
> DEBUG:root:End of Program
> 
> And that table is present in the bustrac database.
> 
> Please suggest how i trace this inability to find database tables to its
> source.
> 
> Thanks again,
> 
> Rich

The Qt documentation for QSqlDatabase.setDatabaseName (qsqldatabase.html <https://doc.qt.io/qt-5.15/qsqldatabase.html#setDatabaseName>) says that the QSQLITE driver will create an empty database if it cannot find the specified one. Maybe the QPSQL driver does the same.

Are you certain that
You are specifying the correct path to the database, and
The version of datasource.py that you are running has the correction I made to the indentation of the block of code that checks for the presence of the required tables. You should get the "repair the database" message box if an empty database is being used.
To be certain of using the required database file you could pass a complete path ("/usr/rich/.../foods.db") to setDatabaseName().

--
Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210605/99f34063/attachment.htm>


More information about the PyQt mailing list