Consider the following project structure:
new_project
├── main.py
└── project
├── __init__.py
├── config.py
└── migrations
├── __init__.py
└── abcd.py
└── efgh.py
└── models
├── __init__.py
└── table.py
If you import other helpful modules within project from your migration files, you would get a nasty ImportError: attempted relative import with no known parent package. This happens since migration_manager.py imports migration modules as top-level packages without taking into account parent packages.
migration_manager.py uses spec = importlib.util.spec_from_file_location(module_name, path) where module_name is the name of the migration file and path is the location of the migration file.
What we need is a way to give users the ability to prefix module_name with a package_name so package/relative imports in migration files work.
A full module_name using the structure outlined above would be project.migrations.abcd.py
Consider the following project structure:
If you import other helpful modules within
projectfrom your migration files, you would get a nastyImportError: attempted relative import with no known parent package. This happens sincemigration_manager.pyimports migration modules as top-level packages without taking into account parent packages.migration_manager.pyusesspec = importlib.util.spec_from_file_location(module_name, path)wheremodule_nameis the name of the migration file andpathis the location of the migration file.What we need is a way to give users the ability to prefix
module_namewith apackage_nameso package/relative imports in migration files work.A full
module_nameusing the structure outlined above would beproject.migrations.abcd.py