tortoise / tortoise/tortoise-orm
default_connection for the model cannot be None
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
I am trying the example code from the README. When running await Tournament.create(name='New Tournament'), it returns the error tortoise.exceptions.ConfigurationError: default_connection for the model <class '__main__.Tournament'> cannot be None.
Tortoise does create the tables in the database, so the connection seems to be working.
I am using postgresql.
To Reproduce
class Tournament(Model):
id = fields.IntField(pk=True)
name = fields.TextField()
def __str__(self):
return self.name
await Tortoise.init(db_url=f"postgres://postgres:<password>@localhost:5432/tortoise",
modules={'models': ['test']})
await Tortoise.generate_schemas()
tournament = await Tournament.create(name='New Tournament')
Expected behavior
Create a new row in the table.
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 by reproducing the README example with PostgreSQL, using Tortoise.init, Tortoise.generate_schemas, and Tournament.create as shown. Trace how the model receives its default connection after initialization and compare that with the successful schema creation. Done means the example creates a new Tournament row without the ConfigurationError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100