Open Mr-NB opened 3 years ago
+1 I have almost the same issue.
When I run aerich init-db
on clean database (PostgresSQL), i get an error tortoise.exceptions.ConfigurationError: No DB associated to model
, but the database is initializing.
When I run aerich migrate --name {some_name}
on already initialized database, then error tortoise.exceptions.ConfigurationError: No DB associated to model
happened again, and no changes applied to database
My tortoise config:
DB_CONN = {
'connections': {
'default': {
'engine': 'tortoise.backends.asyncpg',
'credentials': {
'host': 'localhost',
'port': 5432,
'user': 'postgres',
'password': 'postgres',
'database': 'some-db',
},
}
},
'apps': {
'models': {
'models': ['models'],
'default_connection': 'default'
}
}
}
And models file:
from tortoise.models import Model
from tortoise.fields import IntField, CharField
class SomeModel(Model):
id = IntField(pk=True)
some_field = CharField(max_length=128)
some_field_new = CharField(max_length=128, null=True)
Using latest packages: aerich = "^0.3.3" tortoise-orm = "^0.16.18"
Sorry, I didn't notice that adding aerich.models
to the configuration is a required condition. But you don't think it's better to add it in the aerich itself?
Most people add migrations to an existing project and do not rely on the fact that they will have to change something in the database conf file.
What about adding something like:
list(tortoise_config['apps'].values())[0]['models'].append('aerich.models')
in your cli() function (63 line in aerich.cli.py)?
So what about multiple databases? The first database may don't wan't be choice to store aerich
Yes, that's true, but you can add some kind of error, like:
if 'aerich.models' not in [m for model in tortoise_config['apps'].values() for m in model['models']]:
raise ConfigurationError("You have to add 'aerich.models' in your models")
This will make it much clearer what needs to be done for aerich to work.
That's right
I second this, because the error is really cryptic.
I have the same problem!
same
Hello, I found this post from google results. I'm having the same exception in a clustermaps scraper script. The answers on stackoverflow are specific to their scripts. Could you take a look at this if it's library issue or something i need to do?
`C:\Users\Administrator\Desktop\scraper clustrmaps>python start.py Task exception was never retrieved future: <Task finished name='Task-2' coro=<stats_loop() done, defined at C:\Users\Administrator\Desktop\scraper clustrmaps\controller.py:55> exception=ConfigurationError('No DB associated to model')> Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\models.py", line 262, in db return current_transaction_map[self.default_connection].get() KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Administrator\Desktop\scraper clustrmaps\controller.py", line 59, in stats_loop stats = await db_stats() File "C:\Users\Administrator\Desktop\scraper clustrmaps\controller.py", line 47, in db_stats 'total': await Address.all().count(), File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\models.py", line 1056, in all return QuerySet(cls) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\queryset.py", line 255, in init super().init(model) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\queryset.py", line 88, in init self.capabilities: Capabilities = model._meta.db.capabilities File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\models.py", line 264, in db raise ConfigurationError("No DB associated to model") tortoise.exceptions.ConfigurationError: No DB associated to model Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tortoise\models.py", line 262, in db return current_transaction_map[self.default_connection].get() KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "start.py", line 38, in
When I execute aerich init-db, there is an error tortoise.exceptions.ConfigurationError: No DB associated to model