问题描述
在我当前的项目中,我正在使用破折号数据表和sqlalchemy处理python和SQL数据库之间的数据。
在数据库的当前列中,我创建了一个触发器以生成UUID
CREATE TRIGGER init_uuid BEFORE INSERT ON products
FOR EACH ROW SET NEW.product_id = UUID();
我编辑了破折号数据表并使用它更新到SQL后,触发器丢失了
df = pd.DataFrame(dataset) #update the dataframe to match the edited datatable
df.to_sql('products',con=engine,schema='testdb',index=False,if_exists='replace')
我正在考虑更改触发器插入后,但找不到解决方法。
解决方法
没关系,我是在将数据帧插入数据库之前通过编辑数据帧找到它的
SO44 Add UUID's to pandas DF的答案