Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22577 closed Bug (fixed)

The makemigrations management command has a problem with migrations dir

Reported by: japrogramer@… Owned by: Vidir Valberg Gudmundsson
Component: Migrations Version: dev
Severity: Release blocker Keywords: makemigrations, fail, init, file
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

When the migration folder does not have an init
http://codepad.org/U2nGptor

File "/home/archie/git/django/django/db/migrations/writer.py", line 150, in path basedir = os.path.dirname(migrations_module.__file__)
AttributeError: 'module' object has no attribute '__file__'

the problem lies with makemigrations.py line 134-36 they are checking to see if an init file exists in the migrations dir but it checks using a line that depends on the existence of __init__.py. line 130 , writer.path, following to see where this code comes from led me to line 149 and 150 which need there to be an init file for __file__ to be an attribute there ..
tl;dr
makemigrations checks for an init file using os.path.isdir but with a call that depends on an __init__.py for it treats it as a module before it knows if it is a module

Change History (14)

comment:2 by Tim Graham, 10 years ago

Description: modified (diff)

comment:3 by Tim Graham, 10 years ago

I created an app with an empty migrations folder and ran makemigrations, but did not get an error.

$ mkdir polls/migrations
$ python manage.py makemigrations polls
Migrations for 'polls':
  0001_initial.py:
    - Create model Poll
    - Create model Choice

Could you clarify the steps to reproduce?

comment:4 by Tim Graham, 10 years ago

Resolution: needsinfo
Status: newclosed

comment:5 by nielsen.ruben@…, 10 years ago

I got this problem for some unknown reason. I resolved it by deleting the migrations folder and running makemigrations again

comment:6 by anonymous, 10 years ago

I got this problem too. Could it because I'm on Python 3.

Delete the migrations folder, solve the problem.

comment:7 by david@…, 10 years ago

I got this because I'd created a new migrations folder, but forgot to make it a Python package (no __init__.py) while I was migrating an app from South.

comment:8 by anonymous, 10 years ago

Ran in to this problem today on 1.7b4 and python 3.3. Same result on python 3.4.1.

The "makemigrations" command fails if the migrations folder is empty. It succeeds as soon as I created init.py in the folder. See this gist:

https://gist.github.com/timster/c87117f221690a2dbc72

comment:9 by Tim Graham, 10 years ago

Resolution: needsinfo
Severity: NormalRelease blocker
Status: closednew
Triage Stage: UnreviewedAccepted

comment:10 by Vidir Valberg Gudmundsson, 10 years ago

Owner: changed from nobody to Vidir Valberg Gudmundsson
Status: newassigned

comment:11 by Vidir Valberg Gudmundsson, 10 years ago

Owner: changed from nobody to Vidir Valberg Gudmundsson
Status: newassigned

comment:12 by Vidir Valberg Gudmundsson, 10 years ago

Has patch: set

comment:13 by Víðir Valberg Guðmundsson <valberg@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 3a6cb9f497af4e5eb8351706056eae50a4ed3c45:

Fixed #22577: Python 3 broke on non-module migrations directory

comment:14 by Andrew Godwin <andrew@…>, 10 years ago

In 66a99fa21076529a5e71996a8862597284403727:

Merge pull request #2824 from valberg/22577

Fixed #22577: Python 3 broke on non-module migrations directory

comment:15 by Andrew Godwin <andrew@…>, 10 years ago

In 7f0c207d1b33b03b5bfe89c0e09d4f790c8a1d0a:

[1.7.x] Fixed #22577: Python 3 broke on non-module migrations directory

Note: See TracTickets for help on using tickets.
Back to Top