Search code examples
pythonsqlitepeewee

Add a table to sqlite database


I have a sqlite database with already existing tables

db = SqliteDatabase("C:/database.db")


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

class SymbolModel(BaseModel):
    symbol = CharField()

class EquityModel(BaseModel):
    symbol = ForeignKeyField(SymbolModel, backref='equity')

This works fine.

Now I'd like to add a table, so I've modified my models.py like this:

class EarningsReleaseModel(BaseModel):
    symbol = ForeignKeyField(SymbolModel, backref='earningsrelease')

and called, from a shell:

db.create_tables(EarningsReleaseModel)

However, I get this error:

sqlite3.OperationalError: no such table: earningsreleasemodel

Why?


Solution

  • EarningsReleaseModel.create_table()
    

    Is the correct syntax.