zoukankan      html  css  js  c++  java
  • Django+MySQL开发记录

    1. Djano 与 MySQL

    Django清除数据表中的所有数据

    # 异常方法
    Book.objects.all().delete()  # 对于大型数据集,可能会失效
    Book.objects.raw('''delete from book''')  # 也失效了
    
    文档说明:
    Note that delete() is the only QuerySet method that is not exposed on a Manager itself. This is a safety mechanism to prevent you from accidentally requesting Entry.objects.delete(), and deleting all the entries. If you do want to delete all the objects, then you have to explicitly request a complete query set:
    
    #解决方案
    book = Book.objects.all()
    book.delete()
    # 又是返回值的问题。。。。。
    

    Django批量插入mysql数据库,怎么处理NAN值

    报错提示:
    MySQLdb.err.ProgrammingError: nan can not be used with MySQL
    
    # 解决方案
    data.fillna(value=0)  # 用0填充
    

    Django执行sql语句返回数据

    data = Book.objects.raw(sql_)

    注意:sql_语句中查询的列必须包含主键,data的类型为rawqueryset()

  • 相关阅读:
    2017暑期集训Day 1
    17-06-28模拟赛
    17-06-26模拟赛
    平衡树学习笔记
    指针学习笔记
    17-06-14模拟赛
    17-06-11模拟赛
    17-06-02模拟赛
    17-05-31模拟赛
    培训补坑(day1:最短路&two-sat)
  • 原文地址:https://www.cnblogs.com/lelezuimei/p/15135047.html
Copyright © 2011-2022 走看看