#25313: Document how to migrate from a built-in User model to a custom User 
model
-------------------------------+------------------------------------
     Reporter:  carljm         |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  Documentation  |                  Version:  1.8
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by shaib):

 <brainstorming idea="halfbaked">

 Perhaps it is possible to create a migration operation for changing a
 swappable model.

 Something like:
 {{{
 ChangeSwappableModel(
     setting="AUTH_USER_MODEL",
     old="auth.User",
     new="my_auth.User"
 )
 }}}

 This would be a migration in the `my_auth` app.

 It would need to introspect the database, checking the constraints
 corresponding to `my_auth.User`'s reverse relationships, and verifying
 that they indeed point to the correct table (if they point to `auth_user`,
 change them;  if to `my_auth_user`, leave them be; otherwise, error out).

 To change the swappable model, one would:
 1) Create the set of migrations for creating the new user model, porting
 existing data to it, and  the `ChangeSwappableModel` operation;
 2) Create a "squashing" migration replacing them by just creating the new
 model, so new databases don't have to suffer

 I think with careful migrations embargos in the right times this could be
 made to work. I don't have it in me to work out all the details now, and
 I'm probably missing something essential.

 </brainstorming>

--
Ticket URL: <https://code.djangoproject.com/ticket/25313#comment:7>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.80046d3991c79346323ff2fed5d21028%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to