#25313: Document how to migrate from a built-in User model to a custom User model -------------------------------+------------------------------------ Reporter: Carl Meyer | 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 Pi Delport): These are steps we took to switch our system to a custom `AUTH_USER_MODEL`, for the record: 0. (Take full backups!) 1. Dump the database with: `django-admin dumpdata --natural-primary --natural-foreign --exclude contenttypes.contenttype` 2. Run the JSON dump through a script that rewrites references from the old user model to the new one. (See below.) 3. Define our new custom user model as a `AbstractUser` subclass, with no other schema changes. Update `AUTH_USER_MODEL` to it, nuke all our app's old migrations, and make fresh initial migrations. 4. Create and `django-admin migrate` a fresh new database, and load the rewritten dump. After this point, we can customise our user model with normal Django migrations. The script to rewrite the dump iterates through the list of objects, and rewrites: * The user's' `model` itself. * The user's `user_permissions` field's references. * The `auth.group` `permissions` field's references. * The `auth.permission` and `admin.logentry` `content_type` fields. * Any other references to the old `auth.User` type will need rewriting too. -- Ticket URL: <https://code.djangoproject.com/ticket/25313#comment:11> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.b690c51b4dfb0ccbd6cfed3c08853588%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.