tortoise/tortoise-orm

Usage with Tornado (was: No DB associated to model)

Ouverte

#99 ouverte le 3 févr. 2019

 (17 commentaires) (0 réaction) (0 personne assignée)Python (333 forks)batch import
documentationgood first issuepapercut

Métriques du dépôt

Stars
 (3 863 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

from tortoise.models import Model
from tortoise.fields import *

class Tournament(Model):
    id = IntField(pk=True)
    name = TextField()

if __name__ == "__main__":
    from tortoise import Tortoise, run_async


    async def init():
        # Here we create a SQLite DB using file "db.sqlite3"
        #  also specify the app name of "models"
        #  which contain models from "app.models"
        await Tortoise.init(
            db_url='sqlite://otc.db',
            modules={'models': ['model']} # 传入模块名称,本模块名为 model
        )
        # Generate the schema
        await Tortoise.generate_schemas()


    run_async(init())

    async def dps():
        await Tournament.create(name='Another Tournament')

        # Now search for a record
        tour = await Tournament.filter(name__contains='Another').first()
        print(tour.name)
    run_async(dps())

============================== tortoise.exceptions.ConfigurationError: No DB associated to model

WHY ?

Guide contributeur