tortoise / tortoise/tortoise-orm
Usage with Tornado (was: No DB associated to model)
Open
Nobody has claimed this yet.
documentation
good first issue
papercut
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
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 ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the posted Python example and trace the Tortoise.init configuration and model registration that lead to ConfigurationError: No DB associated to model. Confirm the cause by running the example, then verify that initialization, schema generation, creation, and lookup complete without the error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100