How to custom the table name in peewee?
Asked Answered
C

1

13

I want to define a table which the table name is gobang_server,i write code as follow:

class BaseModel(Model):
    class Meta:
        database = database

class GobangServer(BaseModel):
    time = DateField(default=datetime.datetime.now())
    name = CharField(max_length=64)
    host = CharField(max_length=30)
    port = IntegerField()
    pid = IntegerField()

but i look at PostgreSQL the table name is "gobangserver"?
How can i define with the table name is gobang_server and the class name is not be modified.

Confiscable answered 29/12, 2017 at 7:2 Comment(0)
A
22
class GobangServer(BaseModel):
    ...
    class Meta:
        db_table = 'gobang_server'

In peewee 3.0 it changes from "db_table" to "table_name".

Adelladella answered 29/12, 2017 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.