Django执行Sql语句笔记

使用raw

books=Book.objects.raw('select * from hello_book')  

for book in books:  

   print book



自定义sql
from django.db import connection  
  
cursor = connection.cursor()  
cursor.execute("insert into hello_author(name) VALUES ('郭敬明')")  
cursor.execute("update hello_author set name='韩寒' WHERE name='郭敬明'")  
cursor.execute("delete from hello_author where name='韩寒'")  
cursor.execute("select * from hello_author")  
cursor.fetchone()  
cursor.fetchall()
原文地址:https://www.cnblogs.com/zhouchen0408/p/13153456.html