Flask使用小结【更新ING】

Can't locate revision identified by '3ba21fe709f1' 问题处理

1
2
3
4
5
# taoyi @ TyMac in ~ [16:26:14] 
$ flask db migrate
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Can't locate revision identified by '3ba21fe709f1'
  1. 查询对应表中的数据

    1
    2
    3
    4
    5
    6
    7
    mysql> SELECT * FROM alembic_version;
    +-------------+
    | version_num |
    +-------------+
    | 3ba21fe709f1 |
    +-------------+
    1 row in set (0.00 sec)
  2. 删除版本控制的数据表

    1
    DROP TABLE alembic_version;
  3. 然后删除之前的migrations文件夹,重新生成迁移版本文件夹

    1
    flask db init
  4. 然后重新生成迁移版本文件

    1
    flask db migrate

query.filter常见操作符

  1. equals

    1
    query.filter(User.name == 'ed')
  2. not equals

    1
    query.filter(User.name != 'ed')
  3. LIKE

    1
    query.filter(User.name.like('%ed%'))
  4. IN

    1
    2
    3
    4
    query.filter(User.name.in_(['ed', 'wendy', 'jack']))

    # works with query objects too:
    query.filter(User.name.in_(session.query(User.name).filter(User.name.like('%ed%'))))
  5. NOT IN

    1
    query.filter(~User.name.in_(['ed', 'wendy', 'jack']))
  6. IS NULL

    1
    2
    3
    4
    query.filter(User.name == None)

    # alternatively, if pep8/linters are a concern
    query.filter(User.name.is_(None))
  7. IS NOT NULL

    1
    2
    3
    4
    query.filter(User.name != None)

    # alternatively, if pep8/linters are a concern
    query.filter(User.name.isnot(None))
  8. AND

    1
    2
    3
    4
    5
    6
    7
    # use and_()
    from sqlalchemy import and_
    query.filter(and_(User.name == 'ed', User.fullname == 'Ed Jones'))
    # or send multiple expressions to .filter()
    query.filter(User.name == 'ed', User.fullname == 'Ed Jones')
    # or chain multiple filter()/filter_by() calls
    query.filter(User.name == 'ed').filter(User.fullname == 'Ed Jones')
  9. OR

    1
    2
    from sqlalchemy import or_
    query.filter(or_(User.name == 'ed', User.name == 'wendy'))
  10. MATCH

    1
    query.filter(User.name.match('wendy'))