Peewee insert if not exist
Asked Answered
E

1

12

I am using Python/Mysql and Peewee as ORM. I am stuck in a situation. Suppose i want to insert a row using peewee but check if that row exist skip else insert. Is there any procedure to do so in python using peewee.

Enginery answered 22/6, 2015 at 10:25 Comment(2)
To confirm, you're looking to insert a row if it doesn't exist otherwise don't add it?Chuck
Yes . @Khammel you got it right.Enginery
C
15

Not sure what you've tried already, but I'd suggest the Model.get_or_create() or Model.create_or_get() methods from peewee to do what you're looking for: Peewee Get or Create

Chuck answered 30/6, 2015 at 13:19 Comment(1)
The create_or_get is in master but not in the latest release on PyPI (2.6.1). Expect a new release soon, however.Agrobiology

© 2022 - 2024 — McMap. All rights reserved.