# GSOC 2023 Discussion: Moving models between apps

**URL:** <https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942>\
**Category:** Google Season of Code\
**Created:** [February 18, 2023, 8:32pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942 "2023-02-18T20:32:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevilsAutumn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devilsautumn/32/10408_2.png) [@DevilsAutumn](https://forum.djangoproject.com/u/DevilsAutumn)\
**Post date:** [February 18, 2023, 8:32pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/1 "2023-02-18T20:32:27Z")

</div>

Hello everyone,  
I am a Pre final student from India and want to contribute to a long standing issue of [#24686 (Support for Moving a model between two Django apps) – Django](https://code.djangoproject.com/ticket/24686) as a part of GSOC 2023. This topic is created so that i can discuss , clear doubts and propose the best possible solution.  
There was also some [discussion related to moving models between apps](https://forum.djangoproject.com/t/why-do-we-need-apps/827/20) but its still an unsolved problem.  
Currently models can be moved between the apps using `SeparateDatabaseAndState` but even that might create problems as [mentioned in a comment](https://code.djangoproject.com/ticket/24686#comment:5) by @MarkusH .  
After going through the discussion on the ticket, i have a question :

- If we use `SeparateDatabaseAndState` to move models, can we turn on/off `old_app` ? as we have to apply different operations in both apps so there are dependencies.

---

<div class="post-metadata">

**Author:** ![shaib](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shaib/32/35_2.png) [@shaib](https://forum.djangoproject.com/u/shaib)\
**Post date:** [February 18, 2023, 10:52pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/2 "2023-02-18T22:52:41Z")

</div>

Hi @DevilsAutumn, it’s great that you want to contribute!

Markus essentially answered that question in [a later comment](https://code.djangoproject.com/ticket/24686#comment:7). In order to turn off the old app, you’ll have to edit the migration in the new app to make two changes:

- Remove the dependency on the migration in the old app, and
- Change the operation from a `SeparateDatabaseAndState()` which creates the model in `new_app` only in memory, to a regular `CreateModel()`; this is required for the whole set of migrations to work correctly on an empty database, when `old_app` is no longer available.

I should note, though, that while the issue is indeed long-standing, it seems that someone from Brasil has started working on it only a few weeks ago. Have you coordinated with them?

---

<div class="post-metadata">

**Author:** ![DevilsAutumn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devilsautumn/32/10408_2.png) [@DevilsAutumn](https://forum.djangoproject.com/u/DevilsAutumn)\
**Post date:** [February 20, 2023, 5:38pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/3 "2023-02-20T17:38:57Z")

</div>

hi @shaib , thanks for the quick reply.  
Actually i was doing research on this issue from about a month, trying to reproduce various edge cases with different approaches, but somehow i missed to assign it to myself.  
Yes i saw that that someone from brazil started working on it and i’ll surely connect with him so that we can work together to find the best approach.

---

<div class="post-metadata">

**Author:** ![DevilsAutumn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devilsautumn/32/10408_2.png) [@DevilsAutumn](https://forum.djangoproject.com/u/DevilsAutumn)\
**Post date:** [February 21, 2023, 3:43pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/4 "2023-02-21T15:43:28Z")

</div>

I have opened a [draft PR](https://github.com/django/django/pull/16585) for what was in my mind .  
I have tested the code against some cases on a demo project and it was working fine (even for reverse migration). but there are some cases that need to be tested .  
Adding more about the functionality , With this approach we have to move model without changing anything in the model definition. If we made changes to the moving model then those changes will not be detected with the `MoveModel` operation, running `makemigration` command again will detect those changes and new migration files will be created.  
Only the fields which are referencing the moving model are handled during the `MoveModel` operation.  
We can also modify rename\_model() for moving models between apps but i don’t think that such big change will be preferred.  
Also I’m still trying to figure out how can we create table for moved model on empty database when the old app is removed from `INSTALLED_APPS` .  
Any feedback in appreciable.  
Thanks!

---

<div class="post-metadata">

**Author:** ![DevilsAutumn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devilsautumn/32/10408_2.png) [@DevilsAutumn](https://forum.djangoproject.com/u/DevilsAutumn)\
**Post date:** [February 22, 2023, 6:33pm UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/5 "2023-02-22T18:33:00Z")

</div>

Hi @shaib , It would really helpful if you could please provide a quick feedback so that i know if i’m on the right track or not. 🙂  
Thanks!

---

<div class="post-metadata">

**Author:** ![DevilsAutumn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devilsautumn/32/10408_2.png) [@DevilsAutumn](https://forum.djangoproject.com/u/DevilsAutumn)\
**Post date:** [March 9, 2023, 11:34am UTC](https://forum.djangoproject.com/t/gsoc-2023-discussion-moving-models-between-apps/18942/6 "2023-03-09T11:34:57Z")

</div>

@shaib Based on the discussion we had on the [PR](https://github.com/django/django/pull/16585) I created a draft proposal ["Allow moving a model between apps" -- proposal for Google Summer of Code 2023. · GitHub](https://gist.github.com/DevilsAutumn/7a3cd4567d0aef9d096abf2e0b9f7ffd) .  
and would appreciate your input. Would you be able to take a look and provide some feedback?

Thanks!
