Python 如何使用peewee插入数据?

Python 如何使用peewee插入数据?,python,python-2.7,peewee,Python,Python 2.7,Peewee,我已经描述了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()

我已经描述了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()
然后尝试插入如下数据:

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)

它不会给出任何错误,只是数据库是空的

您需要在之后调用.execute()。更新和删除也一样。

之后需要调用.execute()。更新和删除也一样。

您以后是否
save()
ed?您以后是否
save()
ed?您的意思是
Products.insert(row).execute()
?您能帮助我们,如何在这里按名称获取字段值吗<代码>退货产品。选择()。其中(Products.article==article)。获取()?你是说这个吗
Products.insert(row).execute()
?您能帮助我们,如何在这里按名称获取字段值吗<代码>退货产品。选择()。其中(Products.article==article)。获取()?