Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#22682 closed Bug (fixed)

Makemigrations fails when specifying custom location for migration files

Reported by: ovidiuc4 Owned by: nobody
Component: Migrations Version: master
Severity: Normal Keywords: 1.7b4
Cc: ovidiuc4 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running the initial:

python ./manage.py makemigrations appname

a "migrations" directory is automatically created inside the apps base directory.

When specifying a custom migration file location via MIGRATION_MODULES setting, running initial migration fails to create the directories needed for the migration files. One would expect the same behavior in both situations.

In my case, I want to have all the migrations inside a generic folder named "migrations", setup like so:

# in settings:
MIGRATION_MODULES = dict([(app, 'migrations.' + app) for app in INSTALLED_APPS])

# running makemigrations
python ./manage.py makemigrations appname

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/dev/.envs/atlas2/src/django/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/home/dev/.envs/atlas2/src/django/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/dev/.envs/atlas2/src/django/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/dev/.envs/atlas2/src/django/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/dev/.envs/atlas2/src/django/django/core/management/commands/makemigrations.py", line 54, in handle
    loader = MigrationLoader(None)
  File "/home/dev/.envs/atlas2/src/django/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/home/dev/.envs/atlas2/src/django/django/db/migrations/loader.py", line 144, in build_graph
    self.load_disk()
  File "/home/dev/.envs/atlas2/src/django/django/db/migrations/loader.py", line 71, in load_disk
    module = import_module(module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named appname

I would expect the same behavior in both cases, i.e. have the modules automatically created.

Change History (9)

comment:1 Changed 5 years ago by ovidiuc4

Cc: ovidiuc4 added

Update: I manually created the directories, but it ignored them and added the migration files in their default locations for contrib apps (i.e. inside django installation). I'm using 1.7b4 cloned from git.

Last edited 5 years ago by ovidiuc4 (previous) (diff)

comment:2 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

Looks reasonable, there's nothing in the docs for MIGRATION_MODULES that says the directory must already exist.

comment:3 Changed 4 years ago by mardini

Has patch: set

comment:4 Changed 4 years ago by Moayad Mardini <moayad.m@…>

Resolution: fixed
Status: newclosed

In 56cfa508c796ad317e813647eadd9f7142f6d2dc:

Fixed #22682 -- makemigrations will create MIGRATION_MODULES package

makemigrations will automatically create the package specified
in MIGRATION_MODULES if it doesn't already exist.

Thanks ovidiuc4 for the report.

comment:5 Changed 4 years ago by Andrew Godwin <andrew@…>

In 347cab4faef22e6c903c9a0a407a0da06805a3de:

Merge pull request #2744 from mmardini/MIGRATION_MODULES

Fixed #22682 -- makemigrations will create MIGRATION_MODULES package

comment:6 Changed 4 years ago by Andrew Godwin <andrew@…>

In e4eae5df0ec222fa13d6bac226b3b10c75f3d40d:

[1.7.x] Fixed #22682 -- makemigrations will create MIGRATION_MODULES package

makemigrations will automatically create the package specified
in MIGRATION_MODULES if it doesn't already exist.

Thanks ovidiuc4 for the report.

comment:7 Changed 4 years ago by ovidiuc4

Thanks a lot for implementing this.

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

In 6f4d7f41b1a430febed559b89f18b7db95e2aaa8:

Improved the test for refs #22682.

Thanks apollo13 for the review.

comment:9 Changed 4 years ago by Tim Graham <timograham@…>

In 08a2b3b9cf64c1f1405a24e14500212a613a023c:

[1.7.x] Improved the test for refs #22682.

Thanks apollo13 for the review.

Backport of 6f4d7f41b1 from master

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