Opened 11 years ago
Closed 11 years ago
#21868 closed Bug (fixed)
Empty migrations dir causes exception
Reported by: | Owned by: | ||
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | info@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
]$ python manage.py migrate Operations to perform: Synchronize unmigrated apps: admin, auth, contenttypes, sessions Apply all migrations: (none) Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Installed 0 object(s) from 0 fixture(s) Running migrations: No migrations needed. Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/base.py", line 337, in execute output = self.handle(*args, **options) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/commands/migrate.py", line 140, in handle changes = autodetector.changes(graph=executor.loader.graph) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/autodetector.py", line 34, in changes changes = self._arrange_for_graph(changes, graph) File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/autodetector.py", line 312, in _arrange_for_graph if app_leaf is None and not self.questioner.ask_initial(app_label): File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/questioner.py", line 42, in ask_initial filenames = os.listdir(os.path.dirname(migrations_module.__file__)) AttributeError: 'module' object has no attribute '__file__'
Note: I'm using python3, not tested on python2
After deleting db.sqlite3 and all files in wishes/migrations and got the error above, when running migrate.
Deleting the same, plus the migrations directory solved the problem.
Change History (4)
comment:1 by , 11 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
This happens because in Python 3.3+, __init__.py
is not required; a package without one is considered a namespace package (see PEP 420). Namespace packages do not have a __file__
attribute (it is not actually a required attribute for Python packages); they do have a __path__
attribute (which is a required attribute, and may potentially have more than one path on it).
See #17304 and #21862, and see https://github.com/django/django/pull/2212 for the approach app-loading is taking to this issue.
I think it would be best if migrations did not rely on __file__
but used __path__
instead. It could check if len(migrations_module.__path__) > 1
and raise an error in that case, like app-loading will.
comment:3 by , 11 years ago
Type: | Uncategorized → Bug |
---|
comment:4 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
This happens if the directory exists but does not contain a
__init__.py
file