Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect Model Name Handling #357

Open
pysashapy opened this issue Sep 21, 2024 · 2 comments
Open

[BUG]: Incorrect Model Name Handling #357

pysashapy opened this issue Sep 21, 2024 · 2 comments

Comments

@pysashapy
Copy link

pysashapy commented Sep 21, 2024

In aerich.migrate:234, the current code fails to handle application names with multiple periods (e.g., example.account.models), incorrectly splitting the name and using the second segment.

Current Code:

model = cls._get_model(new_model_describe["name"].split(".")[1])

Suggested Fix:

model = cls._get_model(new_model_describe["name"].split(".")[-1])
@pysashapy
Copy link
Author

I also noticed that after initially running init-db, I can add a new app, but migrations won't be created unless I manually create the folder migrations/{{APP}}. After that, a migration file is created, but with an error: aerich\migrate.py:64 in _get_model (KeyError: {{MODEL NAME}})

Despite this error during migration creation, I can still run migrate, which completes successfully, even though the error in aerich\migrate.py:64 in _get_model occurs during migration generation.

@pysashapy
Copy link
Author

my config

{'apps': {'aerich': {'default_connection': 'default',
                     'models': ['aerich.models']},
          'apptest': {'default_connection': 'default',
                      'models': ['apptest.models']},
          'fasttower.auth': {'default_connection': 'default',
                             'models': ['fasttower.auth.models']}},
 'connections': {'default': {'credentials': {'file_path': 'full_path/to/db.sqlite3'},
                             'engine': 'tortoise.backends.sqlite'}},
 'timezone': 'UTC',
 'use_tz': True}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant