[英]How to specify table for inserting data using peewee?
I use the following code to inserting data in DB: 我使用以下代码在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()
And connection function: 并连接功能:
def dbConnection(host, user, password):
return peewee.MySQLDatabase("test", host=host, port=3306, user=user, passwd=password)
How to set table name in which I insert data? 如何设置要在其中插入数据的表名?
If you take a look at the docs on peewee model options 如果您查看有关peewee模型选项的文档
There is an option you can specify in class Meta
called db_table
which is the name of the table to store data. 您可以在class Meta
指定一个选项,称为db_table
,这是用于存储数据的表的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.