#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 aaugustin):

 I did it at least twice. Unfortunately I don't remember all the details.

 I think a reasonable procedure is:

 1. Create a custom user model identical to `auth.User`, call it `User` (so
 many-to-many tables keep the same name) and set `db_table='auth_user'` (so
 it uses the same table)
 2. Throw away all your migrations
 3. Recreate a fresh set of migrations
 4. Sacrifice a chicken, perhaps two if you're anxious; also make a backup
 of your database
 5. Truncate the `django_migrations` table
 6. Fake-apply the new set of migrations
 7. Unset `db_table`, make other changes to the custom model, generate
 migrations, apply them

 It is highly recommended to do this on a database that enforces foreign
 key constraints. Don't try this on SQLite on your laptop and expect it to
 work on Postgres on the servers!

--
Ticket URL: <https://code.djangoproject.com/ticket/25313#comment:2>
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.e11b56d5e7781a8643edca9dd6bdcff4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to