Opened 8 years ago

Last modified 8 months ago

#25765 assigned Cleanup/optimization

makemigrations and app_label are incompatible

Reported by: ograycode Owned by: Bhuvnesh
Component: Documentation Version: 1.8
Severity: Normal Keywords:
Cc: Bhuvnesh Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Repo steps:

  • Create a new app called "testapp"
  • Add one model to the models.py with a meta class and app_label which are different then your current one.
  • Run "manage.py makemigrations testapp"

On the third step, it will state that there are no changes. If you remove the custom app_label and run makemigrations again it will pick up on the new model. If you change app_label once again, it will see that as a deletion of the model.

I believe that it should either be explicitly documented, or that app_label should have no bearing on makemigrations.

Change History (4)

comment:1 by Marten Kenbeek, 8 years ago

Component: UncategorizedDocumentation
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

The behaviour is correct. By changing the app_label, you are effectively moving the model to a different app without changing the file location. If the new app label is the label of a valid Django app, you will be able to create migrations for that model using the explicitly defined app_label.

Django currently does not support moving a model from one application to another. That's why it sees the model as a new model when you remove the explicit app label, and sees it as a deleted model when you change the app label again. The new app label you define is not recognized as a valid app, so it is treated as an unmigrated app (or the model might be ignored by manage.py migrate - something to figure out as well).

We can expand the description of Meta.app_label and link to AppConfig.label to clarify that changing the app_label also changes the app in which the model lives according to Django. The django-admin page has a short section about the "app name" used by various commands. I suggest we change the terminology to app label to clarify its meaning and be consistent with the rest of the documentation. This section could also be a bit more elaborate.

comment:2 by Sarah Boyce, 8 months ago

Cc: Bhuvnesh added

Hi Bhuvnesh! I just saw this ticket and thought that your GSoC project of moving models between apps is quite related. Would this need to be closed once your PR is accepted or would the documentation still be valid?

comment:3 by Bhuvnesh, 8 months ago

Hi Sarah! Once My PR is accepted, this ticket can be closed. Changing the app_label or actually moving the model to other app generates exactly the same migrations. So i don't think we would need to document this.
(I'll add this case in my demo project too.)

comment:4 by Bhuvnesh, 8 months ago

Owner: changed from nobody to Bhuvnesh
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top