简体   繁体   English

从 sqlalchemy 插入数据后,如何在 MySQL 上创建 UUID 触发器?

[英]how to create a UUID trigger on MySQL after data has been inserted from sqlalchemy?

In my current project I am using dash datatable and sqlalchemy to handle the data between python and SQL database.在我当前的项目中,我使用 dash 数据表和 sqlalchemy 来处理 python 和 SQL 数据库之间的数据。

In the current column of database I have created a trigger to generate a UUID在数据库的当前列中,我创建了一个触发器来生成 UUID

CREATE TRIGGER init_uuid BEFORE INSERT ON products
    FOR EACH ROW SET NEW.product_id = UUID();

after I edited the dash datatable and update it to the SQL using this, the trigger is missing在我编辑破折号数据表并使用此将其更新为 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')

I was thinking to change the trigger AFTER INSERT but I can not find the solution.我想在插入后更改触发器,但找不到解决方案。

nevermind I have found it by editing the dataframe before inserting it to the database没关系,我在将数据框插入数据库之前通过编辑数据框找到了它

Answer by SO44 Add UUID's to pandas DF SO44 的回答将 UUID 添加到Pandas DF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM