django.db.utils.DatabaseError:线程错误(sql_server环境)

报错信息

django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias ‘default’ was created in thread id 8576 and this is thread id 11652

场景

  • 我在django开发的时候用的是sql_server数据库
  • 向数据库插入一条数据
  • 在脚本中插入数据是要加代码cursor.connection.commit()的,因为没有这个语句插不进去数据
  • 但是在django中加了这个语句就会报这个错误
  • 分享部分代码,把后面那个注释就行了,当然注释了也能插入进去数据的,不知道为啥
        cursor.execute("INSERT INTO MEMBER(mno, mpassword, mname, mphone, mpost, madress) VALUES ('{}','{}','{}','{}','{}','{}')".format(account, password, name, telephone, email, address))
            #cursor.connection.commit()#提交修改

你可能感兴趣的:(Django)