我使用以下代码在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)
如何设置我插入数据的表名?
答案 0 :(得分:1)
如果您查看peewee model options
上的文档您可以在class Meta
中指定一个名为db_table
的选项,该选项是用于存储数据的表的名称。