tortoise/tortoise-orm

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

Open

#99 aberto em 3 de fev. de 2019

Ver no GitHub
 (17 comments) (0 reactions) (0 assignees)Python (333 forks)batch import
documentationgood first issuepapercut

Métricas do repositório

Stars
 (3.863 stars)
Métricas de merge de PR
 (Mesclagem média 15d 7h) (9 fundiu PRs em 30d)

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 ?

Guia do colaborador