django如何直接对数据库进行插入操作?

通过psycopg2与数据库进行连接,发现可以进行查询操作:

sql = """select * from oms.cus_questions WHERE que_no = '20170606174216'"""
查询到的结果:
[['20170606174216', '1000', '1220', None, None, None, '1002', None, None, None, '提现到账查询', '未到账', None, None, None, None, False, datetime.datetime(2017, 6, 6, 17, 42, 7, 7293, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=480, name=None)), None, datetime.datetime(2017, 6, 6, 17, 42, 7, 7293, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=480, name=None)), None]]

修改主键值,将上面查询的结果,再次插入数据库,修改sql:

sql = """insert into oms.cus_questions("que_no", "loan_no", "usr_id", "phone_no", "ctif_id_no", "usr_name", "que_type", "que_status", "flow_no", "do_usr_id", "que_title", "que_description", "que_solution", "que_doing_tm", "crt_done_tm", "que_ower_id", "is_deleted", "crt_tm", "crt_usr", "last_upd_tm", "last_upd_usr") values('20170606174216', '1000', '1220', None, None, None, '1002', None, None, None, '提现到账查询', '未到账', None, None, None, None, False, datetime.datetime(2017, 6, 6, 17, 42, 7, 7293, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=480, name=None)), None, datetime.datetime(2017, 6, 6, 17, 42, 7, 7293, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=480, name=None)), None) """

报错:
psycopg2.ProgrammingError: 错误: 字段 "none" 不存在
LINE 1: ...d_usr") VALUES ('20270606174216', '1000', '1220', None, None...

阅读 3.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏