I have a website running with a mysql database using the sql-alchemy package that has suddenly broken. I have done some research and found that the expected issue is that th
The problem is covered on the github issues thread - https://github.com/flask-admin/flask-admin/issues/1588
Basically, the flask-admin pip package is out of date, in regards the latest sqlalchemy pip package. In that specific area,
cls, key = identity_key(instance=obj)
sqlalchemy is now returning 3 objects, but flask-admin is only expecting 2, hence the error.
The real solution for this is to wait until a new flask-admin version is uploaded to pip, until then, you've a few options.
fields.py filesqlalchemy to version 1.2.0b3. You can do this in your requirements.txt file, or manually with a pip upgrade install, pip install --upgrade sqlalchemy==1.2.0b3flask-admin's master branch in their github repository, install that version of flask-admin with the pip location of git+https://github.com/flask-admin/flask-admin. Again, you do this in your requirements.txt file, or with a pip upgrade install, pip install --upgrade git+https://github.com/flask-admin/flask-admin.My personal preference, and what I've done, is option 3. If you look through the code itself, it's a line the maintainers want to remove, anyway, and how they're dealing with it is better, and in general with these things, I prefer to go forward (latest version of flask-admin) rather than holding things back (rollback sqlalchemy to a previous version), and certainly better than manually editing the raw code.
I was also having this issue. I got the hacks (as described above) to work, but looking at the discussions on https://github.com/wtforms/wtforms/issues/373 and https://github.com/flask-admin/flask-admin/issues/1588, it looked like support for wtforms_sqlalchemy is not as good as wtforms_alchemy.
So, I installed wtforms_alchemy
pip install wtforms_alchemy
and replaced wtforms_sqlalchemy with wtform_alchemy in my project
from wtforms_alchemy.fields import QuerySelectField
and my project worked the same.