tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

default_connection for the model cannot be None

Open Cikmo opened this issue 2 years ago • 5 comments

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.

Cikmo avatar Jul 24 '22 19:07 Cikmo