tortoise / tortoise/tortoise-orm

default_connection for the model cannot be None

Open
#1,188 6 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.