Solved failing to make the code to connect to a database in PyQt5
-
Hi and welcome to devnet,
Your addDatabase call is invalid.
If your version of PyQt is recent enough your likely do not have the MySQL backend because it's currently not prebuilt anymore due to a change of licensing from Oracle.
-
@adrian88888888
Furthermore, you have.db.open()
andMyTree.setModel(.model)
, is that was is actually in your code? -
@SGaist thanks!, what are my options then? should i go to PyQy4?
-
Which version are you currently using ?
-
@SGaist I don't know how to get the exact versions but they are:
-PySide2
-PyQt5
-MySQL 8.0.........................................................................................................................................................
@JonB instead of
DataBase = db.open()
maybe it is justdb.open()
?, i put that because of something in the documentation, i suspect that's wrong in some way, in my code there's nothing calledDataBase
but
MyTree.setModel(.model)
exist in the code, i created the treeView -
How did you install these packages ?
-
@SGaist
for being new i can reply every 10 minutes sorry
1-pip install PySide2
2-I did not install PyQt5(i guess it comes somehow inside pip install PySide2)
3-MySQL from the page of the comunity sever: link textin the documentation says that is compatible, in this table link text, it says in the 3rd row: MySQL or MariaDB (version 5.0 and above)
-
Then pip can give you the version you installed.
PyQt5 and PySide2 are two different projects that are unrelated.
What you can do is install a version that uses a version of Qt that is less recent so you'll have the plugin already available.
-
@SGaist the pip showed me that the version of Pyside2 is 5.15.0
ohh i remember now, i installed "pip install PyQt5", im newbie so i hardly understand what i'm doing, the version of PyQt5 is 5.13.2
so you mean that i should uninstall PyQt5 and put an older version like PyQt4? or i should have an older version of Pyside2?
what gets me really lost is that the documentation says that is compatible here, in the 3rd row of the table
-
Compatible it is. What is happening is that Oracle changed their licensing therefore the plugin is currently not provided pre-built anymore.
So, did you try your code with both libraries ?
-
@SGaist i changed to another database (sqlite) and it worked!, thanks a lot, i wouldn't figured it out on my own
-
If you need a remote database system PostgreSQL is also a very good solution.
-
@SGaist yes i imagine that there's other solutions, but i'm going basic for now