#24686: Support for Moving a model between two Django apps
-------------------------------+------------------------------------
     Reporter:  Alex Rothberg  |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  Migrations     |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  1
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by wtayyeb):

 Hi again.
 Unlike my previous comment and approach, I found that `RenameModel`
 operation is well written even for moving models, so I update it and
 `MigrationAutodetector` to handle moving models.
 The move mechanism is completely without `SeparateDatabaseAndState` and it
 will produce at least 2 migrations one for old_app and one for new_app
 like below.

 00zz_new_created_migration_at_old_app.py
 {{{#!python
 class Migration(migrations.Migration):
     dependencies = [
         ('new_app', '00xx_some_migration'),
         ('old_app', '00yy_pre_migration'),
         # ...
     ]
     operations = [
         operations.RenameModel(
             old_name='MyModel',
             new_name='MyModel',
             new_app_label='new_app',
         ),
     ]
 }}}

 00vv_new_created_migration_at_new_app.py
 {{{#!python
 class Migration(migrations.Migration):
     initial = True
     dependencies = [
         ('new_app', '00xx_some_migration'),
         ('old_app', '00zz_new_created_migration_at_old_app'),
     ]
     operations = [
         operations.MoveModelPlaceholder(
             old_name='MyModel',
             new_name='MyModel',
             new_app_label='new_app',
             comment='this is a required noop operation to construct
 dependencies for moving model',
         ),
     ]
 }}}

 note that `MoveModelPlaceholder` is a noop operation to construct the
 dependencies and let forward and backward migrations without problem.

 the code is in  [https://github.com/django/django/pull/11920 PR]

-- 
Ticket URL: <https://code.djangoproject.com/ticket/24686#comment:13>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.3d61a33f5adc80bc24d3b06638ad1d30%40djangoproject.com.

Reply via email to