当前位置:Gxlcms > 数据库问题 > Django数据库操作的注意事项《特别篇》!

Django数据库操作的注意事项《特别篇》!

时间:2021-07-01 10:21:17 帮助过:8人阅读

pymysql from allinone.settings import BASE_DIR class Mysqls(object): def __init__(self): # 读取配置文件 self.connect() def connect(self): try: self.connection = pymysql.connect(host="192.168.0.105", user="root", password="123456", database="allinones") self.cursor = self.connection.cursor() except Exception as e: print(e) # kill() # 获取所以数据 def get_all(self, sql): try: self.cursor.execute(sql) return self.cursor.fetchall() except: self.connection() self.cursor.execute(sql) return self.cursor.fetchall()
  def get_close(self):
self.cursor.close()



猜测引起的原因,可能为数据库引擎有表级锁或者行级锁的原因,与模型对象查询时出现冲突,又或者与数据库链接过多,没有关闭。

Django数据库操作的注意事项《特别篇》!

标签:connect   读取配置   fetchall   nec   cep   获取   user   原因   出现   

人气教程排行