DJango操作MySQL数据库
增加:創(chuàng)建實(shí)例,并調(diào)用save
更新:a.獲取實(shí)例,再sava;b.update(指定列)
刪除:a. filter().delete(); b.all().delete()
獲取:a. 單個(gè)=get(id=1) ;b. 所有 = all()
過濾:filter(name='xxx');filter(name__contains='');(id__in = [1,2,3]) ;
icontains(大 小寫無關(guān)的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
數(shù)量: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()?
轉(zhuǎn)載于:https://blog.51cto.com/kevinhao/1699613
總結(jié)
以上是生活随笔為你收集整理的DJango操作MySQL数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【C语言】接收字符,大小写字符相互转换后
- 下一篇: 【SQL】使用调用层接口