向数据库添加随机数据

需要注意的是 %s 引用中文字符,需要加上引号,否则会报错找不到这个列名

    def insert_data(self):
        lst_first = ["啊", "的", "发"]
        lst_last = ["是", "吃","了"]
        shuzi = random.choice(["1","2"])
        ret1 = random.choice(lst_first)
        ret2 = random.choice(lst_last)
        ret3 = random.choice(lst_last)
        name = [str(ret1+ret2+ret3)]
        names = [shuzi]
        print(name,names)

        db = "INSERT INTO tbl_nutrition_tag (tag_name, tag_type, update_time, create_time) VALUES (('%s'), 1, '2019-09-04 11:07:03', '2019-09-04 11:07:03');" % "".join(name)

        myQuery("health_business", db)

 

你可能感兴趣的:(python)