Migrations not found when only .pyc files are available (e.g. in a frozen environment)
|Reported by:||danielmenzel||Owned by:||nobody|
|Severity:||Normal||Keywords:||migrations, .pyc, frozen, cx_Freeze|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When only .pyc files are available, for example in a frozen environment after running cx_Freeze or similar tools, migrations no longer work: the migrate command does not find any migrations to apply, and produces the following output:
Operations to perform: Synchronize unmigrated apps: <some apps that really have no migrations> Apply all migrations: (none) Synchronizing apps without migrations: Creating tables... Creating table <some tables> Installing custom SQL... Installing indexes... Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Subsequent operations then fail because the database is unmigrated.
The typical content of a frozen migrations folder looks like this:
django contrib contenttypes migrations __init__.pyc 0001_initial.pyc
Due to issue https://code.djangoproject.com/ticket/23237, there was a change in django.db.migrations.loader (https://code.djangoproject.com/changeset/267630ad50c69ebfe594de37a0636264aa5be7d6): Previously, migrations were found if they had a .py, .pyc, or .pyo extension. Now only migrations with .py extensions are found.
Perhaps it would be possible to add a check if Django is running in a frozen environment:
if hasattr(sys, 'frozen'): extensions = ('.py', '.pyc') else: extensions = ('.py', ) ... if name.endswith(extensions): ...
or make the list of allowed extensions configurable by the user.
Change History (19)
comment:1 Changed 2 years ago by timgraham
- Cc andrewgodwin added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted