tortoise/tortoise-orm

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

Open

#99 ouverte le 3 févr. 2019

Voir sur GitHub
 (17 commentaires) (0 réactions) (0 assignés)Python (333 forks)batch import
documentationgood first issuepapercut

Métriques du dépôt

Stars
 (3 863 stars)
Métriques de merge PR
 (Merge moyen 15j 7h) (9 PRs mergées en 30 j)

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