如何使用peewee指定用于插入数据的表?

时间:2017-11-15 19:26:02

标签: python python-2.7 peewee

我使用以下代码在DB中插入数据:

db = dbConnection("localhost", "root", "")

class Products(peewee.Model):
    article = peewee.TextField()
    name = peewee.TextField()
    price = peewee.TextField()
    price_distributor = peewee.TextField()
    price_discount = peewee.TextField()

    class Meta:
        database = db

Products.create_table()
book = Products(article="1", name="2", price="3", price_distributor="4", price_discount="5")
book.save()

连接功能:

def dbConnection(host, user, password):
    return peewee.MySQLDatabase("test", host=host, port=3306, user=user, passwd=password)

如何设置我插入数据的表名?

1 个答案:

答案 0 :(得分:1)

如果您查看peewee model options

上的文档

您可以在class Meta中指定一个名为db_table的选项,该选项是用于存储数据的表的名称。