DJango操作MySQL数据库
生活随笔
收集整理的這篇文章主要介紹了
DJango操作MySQL数据库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
增加:創建實例,并調用save
更新:a.獲取實例,再sava;b.update(指定列)
刪除:a. filter().delete(); b.all().delete()
獲取:a. 單個=get(id=1) ;b. 所有 = all()
過濾:filter(name='xxx');filter(name__contains='');(id__in = [1,2,3]) ;
icontains(大 小寫無關的LIKE),startswith和endswith, 還有range(SQLBETWEEN查詢)'gt', 'in', 'isnull', 'endswith', 'contains', 'lt', 'startswith', 'iendswith', 'icontains','range', 'istartswith'排序:order_by("name") =asc ;order_by("-name")=desc
返回第n-m條:第n條[0];前兩條[0:2]
指定映射:values
數量:count()
聚合:from django.db.models import Min,Max,Sum objects.all().aggregate(Max('guest_id'))
原始SQL
123 cursor = connection.cursor()cursor.execute('''SELECT DISTINCT first_name ROM people_person WHERE last_name = %s""", ['Lennon'])row = cursor.fetchone()?
轉載于:https://blog.51cto.com/kevinhao/1699613
總結
以上是生活随笔為你收集整理的DJango操作MySQL数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【C语言】接收字符,大小写字符相互转换后
- 下一篇: 【SQL】使用调用层接口