Hello Django developers,

I'm new to the community and I'm not sure if this is the right place to ask 
my question, so please let me know if there's a more appropriate channel 
for this type of discussion.

I would like to ask for feedback on my approach. I have found what I 
believe to be the best way to move a model from one app to another in 
Django. It involves four separate operations in at least 3 different 
migrations:

   1. 
   
   Rename table operation: renames the physical table name on the database. 
   This operation should be a SeparateDatabaseAndState operation and only 
   change the database, without changing any state.
   2. 
   
   Create table operation: moves the model code to the new app, and creates 
   a CreateModel only in state, with a SeparateDatabaseAndState operation.
   3. 
   
   Update all foreign keys that point to the moved model.
   4. 
   
   Delete the old model table, but only in state, using a 
   SeparateDatabaseAndState operation.
   

I've implemented this logic in a new method called "generate_moved_models" 
in MigrationAutodetector. 
<https://github.com/durvalcarvalho/django/blob/b8a5155f474de8dadf92495d1ec9c668860aeb27/django/db/migrations/autodetector.py#L616>
 

This approach didn't break any existing tests, and now I'm focused on 
writing the text using the moving model feature with other operations.

Thank you all in advance for your feedback on this approach.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/70112aa3-fe34-4943-8134-a571c5a875e5n%40googlegroups.com.

Reply via email to