Opened 11 years ago

Closed 11 years ago

#21283 closed Bug (fixed)

Migrations created in wrong directory for models defined in model package

Reported by: anonymous Owned by: Markus Holtermann
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: info@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django supports to split a bunch of models into a separate Python modules which are placed in a models Python package. However the django.db.migrations.writer.MigrationWriter does not reflect this fact in its path property.

The solution is easy:

If myapp.models is a Python app_module (currently line 61) has a __path__ attribute. If it is a Python module there is no such attribute.

I'm going to write a patch and open a pull request for further discussion.

Change History (8)

comment:1 by Tim Graham, 11 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Markus Holtermann <info@…>, 11 years ago

Has patch: set
Needs tests: set
Owner: changed from Markus Holtermann to anonymous
Status: newassigned

The pull request is at https://github.com/django/django/pull/1763

Right know I don't have a clue how to write a test case for this issue.

comment:3 by Markus Holtermann, 11 years ago

Cc: info@… added
Owner: changed from anonymous to Markus Holtermann

comment:4 by Tim Graham, 11 years ago

Could you make a separate test app like "migrations_model_package" and make sure migrations are properly generated there?

comment:5 by loic84, 11 years ago

@timo, shouldn't this use the app cache methods that you reworked at some point to better deal with models in exotic locations?

As for testing, dunno if this is going to play nice with MIGRATION_MODULES that we need to use in tests.

comment:6 by Tim Graham, 11 years ago

That would be get_app_path() introduced in 31c13a99bb9ebdaf12ccab4e880c5da930d86e79, I think.

comment:7 by loic84, 11 years ago

I had a go at this https://github.com/django/django/pull/1772, feedback welcome.

comment:8 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 584110417f6a3c16cc0c6723825a21940a9a2bc4:

Fixed #21283 -- Added support for migrations if models is a package.

Thanks Markus Holtermann for the report.

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