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()
posted @ 2020-06-17 17:01  一抹浅蓝  阅读(278)  评论(0编辑  收藏  举报