Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#22577 closed Bug (fixed)

The makemigrations management command has a problem with migrations dir

Reported by: japrogramer@… Owned by: valberg
Component: Migrations Version: master
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 Changed 3 years ago by Tim Graham

Description: modified (diff)

comment:3 Changed 3 years ago by Tim Graham

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 Changed 3 years ago by Tim Graham

Resolution: needsinfo
Status: newclosed

comment:5 Changed 3 years ago by nielsen.ruben@…

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

comment:6 Changed 2 years ago by anonymous

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

Delete the migrations folder, solve the problem.

comment:7 Changed 2 years ago by david@…

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 Changed 2 years ago by anonymous

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 Changed 2 years ago by Tim Graham

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

comment:10 Changed 2 years ago by valberg

Owner: changed from nobody to valberg
Status: newassigned

comment:11 Changed 2 years ago by valberg

Owner: changed from nobody to valberg
Status: newassigned

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

Resolution: fixed
Status: assignedclosed

In 3a6cb9f497af4e5eb8351706056eae50a4ed3c45:

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

comment:14 Changed 2 years ago by Andrew Godwin <andrew@…>

In 66a99fa21076529a5e71996a8862597284403727:

Merge pull request #2824 from valberg/22577

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

comment:15 Changed 2 years ago by Andrew Godwin <andrew@…>

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