question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support insert ignore , on duplicate key update or replace for mysql?

See original GitHub issue

support insert ignore , on duplicate key update or replace for mysql. I want to use insert_many to insert data into mysql. But one of column is a UNIQUE KEY so how to solve this.

I hope it can like this execute(ignore=True)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mikemillcommented, May 8, 2017

Have you tried using the upsert() syntax, or could you share the insert statement you’re executing along with the generated SQL?

The big problem with upsert() in MySQL is that it generates a REPLACE INTO which deletes the matching rows and re-inserts them. If there is a foreign key to that row then those keys are taken into account (either cascading the delete or blocking the delete). However, an INSERT INTO ... ON DUPLICATE KEY UPDATE doesn’t have this issue.

2reactions
631068264commented, Sep 17, 2016

OK . I find only ignore in InsertQuery.on_conflict. But what is INSERT OR IGNORE INTO ? In Mysql only INSERT IGNORE INTO is right( I didn’t use PostgreSQL or SQLite ). I think you should divide peewee into different versions for different DBMS and it can adapt to some features in different DBMS.

I like peewee than SQLAlchemy because the former‘s document and api design are much more beautiful than the latter. I hope peewee become more perfect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY ...
If you use both INSERT IGNORE and ON DUPLICATE KEY UPDATE in the same statement, the update will still happen if the insert...
Read more >
13.2.7.2 INSERT ... ON DUPLICATE KEY UPDATE Statement
The ON DUPLICATE KEY UPDATE clause can contain multiple column assignments, separated by commas. The use of VALUES() to refer to the new...
Read more >
Duplicate and Ignore on MySQL Inserts
Duplicate and Ignore on MySQL Inserts. MySQL table primary keys and unique indexes prevent multiple rows with the same index from being added...
Read more >
MySQL INSERT ON DUPLICATE KEY UPDATE
This tutorial shows you how to use MySQL INSERT ON DUPLICATE KEY UPDATE statement effectively by practical examples.
Read more >
INSERT ON DUPLICATE KEY UPDATE - MariaDB
INSERT ... ON DUPLICATE KEY UPDATE is a MariaDB/MySQL extension to the INSERT statement that, if it finds a duplicate unique or primary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found