1.我是参照网上的一个flask例子,http://www.pythondoc.com/flas...很苦逼,进行操作的。
2.当我在数据库原有的一张表里 添加额外的两个属性,执行migrate操作
3.之后 我去查询数据库时,涉及这两个变量总是报同样的错误,具体如下:
lower()函数 字符串应该都有这个属性的呢
我将原来的数据库进行删除,重建数据库 还是报同样的错误。有遇到过相同问题的同学,可以给点提示,谢谢!
问题一:我删除的时候,是否还有一些版本迁移的文件未删干净
问题二:是否是flask带有的缺陷,如何解决
Post the code of the two attributes you added
In error
'String' object
不是字符串类型,是 sqlalchemy 里的 Field 类String
Update:
According to the code you posted,
about_me
和last_seen
中db.column
拼错了应该是db.Column
There is one thing that is not mentioned in the database migration book. Every migration requires re-creating the migration script and then using the script to migrate.
For details, please see: https://zhuanlan.zhihu.com/p/...
Question 1: As you said, this kind of problem will still occur if you delete the entire original database and rebuild it, which means it is not a problem with the version migration file.
Question 2:
sqlalchemy
It’s just an extension provided by other flask developers, so it has nothing to do with flask itself.As mentioned above,
String
is not the data type ofpython
itself, it is provided byString
不是python
本身的数据类型,是sqlalchemy
提供的,所以应该是你自己定义的Model
, so it should be theModel
class defined by yourself mistake. You'd better provide the code for the error part, otherwise it will be difficult to analyze.The specific code is as above
My query command
user = models.User.query.get(1)
print user.email (normal) user.about_me (error report) user.last_seen (error report)
If you want to capitalize Column, you should not get an error