Home  >  Q&A  >  body text

python - flask 数据库查询总是报错,非常奇怪的现象。

1.我是参照网上的一个flask例子,http://www.pythondoc.com/flas...很苦逼,进行操作的。
2.当我在数据库原有的一张表里 添加额外的两个属性,执行migrate操作
3.之后 我去查询数据库时,涉及这两个变量总是报同样的错误,具体如下:


lower()函数 字符串应该都有这个属性的呢
我将原来的数据库进行删除,重建数据库 还是报同样的错误。有遇到过相同问题的同学,可以给点提示,谢谢!
问题一:我删除的时候,是否还有一些版本迁移的文件未删干净
问题二:是否是flask带有的缺陷,如何解决

阿神阿神2764 days ago741

reply all(5)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 10:05:58

    • Post the code of the two attributes you added

    • In error 'String' object 不是字符串类型,是 sqlalchemy 里的 Field 类 String

    Update:
    According to the code you posted,about_melast_seendb.column 拼错了应该是 db.Column

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:05:58

    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/...

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:05:58

    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: sqlalchemyIt’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 of python itself, it is provided by String不是python本身的数据类型,是sqlalchemy提供的,所以应该是你自己定义的Model, so it should be the Model class defined by yourself mistake. You'd better provide the code for the error part, otherwise it will be difficult to analyze.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:05:58

    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)

    reply
    0
  • PHPz

    PHPz2017-04-18 10:05:58

    If you want to capitalize Column, you should not get an error

    reply
    0
  • Cancelreply