Search code examples
pythonpython-2.7peewee

How to insert data using peewee?


I have described a model of peewee:

class Products(peewee.Model):
    article = peewee.CharField(primary_key=True)
    name = peewee.CharField()
    price = peewee.FloatField()
    price_distributor = peewee.FloatField()
    price_discount = peewee.FloatField()

    class Meta:
        database = get_db_connection()

Then tried to insert data like:

row = {
                'article': row[0].value,
                'name': row[1].value,
                'price': row[2].value,
                'price_distributor': row[3].value,
                'price_discount': row[4].value
            }

# Insert
Products.insert(row)

It does not give any errors, just database is empty


Solution

  • You need to call .execute() afterwards. Same for update & delete.