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.
Asked
Active
Viewed 8,266 times
12
-
To confirm, you're looking to insert a row if it doesn't exist otherwise don't add it? – khammel Jun 29 '15 at 21:00
-
Yes . @Khammel you got it right. – Afroz Alam Jun 30 '15 at 12:43
1 Answers
14
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

khammel
- 2,047
- 1
- 14
- 18
-
The `create_or_get` is in master but not in the latest release on PyPI (2.6.1). Expect a new release soon, however. – coleifer Jul 01 '15 at 23:37