SQL-alchemy: ValueError too many values to unpack?

做~自己de王妃 提交于 2019-11-29 02:44:59

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.

  1. Manually go in and edit that fields.py file
  2. As detailed in that issues thread, limit sqlalchemy 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.0b3
  3. As the fix is in flask-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.

Thomas Morrison

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!