{ "info": { "author": "Luke Plant", "author_email": "L.Plant.98@cantab.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "===============================\ndjango_custom_user_migration\n===============================\n\n.. image:: https://img.shields.io/pypi/v/django_custom_user_migration.svg\n :target: https://pypi.python.org/pypi/django_custom_user_migration\n\n\ndjango_custom_user_migration creates migrations for you to move an existing\nDjango project that uses ``django.contrib.auth.models.User`` to using a custom user\nmodel.\n\nFree software: BSD license\n\nUse case\n--------\n\nYou are currently using Django's ``django.contrib.auth.models.User`` model in a\ndeployed project, but want to migrate to a model that is under your own control, or\nprovided by a 3rd party.\n\nPrerequisites\n-------------\n\n* Django 1.8 or later\n* Python 2.7 or Python 3.3+\n\nYou must have ensured that everywhere in your project (including 3rd party\nlibraries) you are using ``AUTH_USER_MODEL`` and\n``django.contrib.auth.get_user_model()`` rather than ``\"auth.User\"`` and\n``django.contrib.auth.models.User``.\n\n\nUsage\n-----\n\nThere are a lot of steps below, but it is almost all copy/paste, and with no\ncomplications you could be done in 5 minutes. It assumed you will perform all\nthese steps apart from the last in your development environment.\n\n1. Install ``django_custom_user_migration`` to your project::\n\n pip install django_custom_user_migration\n\n2. Add ``\"django_custom_user_migration\"`` to your ``INSTALLED_APPS``.\n\n You now have some management commands for creating migrations that we\n will use later.\n\n3. Create a custom user model which is identical to Django's ``auth.User``, but\n in an app in your own project. For this process to work correctly, you will\n need to create a new app for this model - we'll call it ``accounts`` from now\n on::\n\n # accounts/models.py\n\n from django_custom_user_migration.models import AbstractUser\n\n class User(AbstractUser):\n pass\n\n The model can be called anything you want. Remember to add this app to your\n ``INSTALLED_APPS``.\n\n Don't add additional fields at this point, and don't change\n ``AUTH_USER_MODEL`` yet.\n\n We avoid using ``django.contrib.auth.models.AbstractUser`` at this point, or\n a user model from some 3rd party library, because we get problems with\n ``related_name`` clashes that we can't work around. Later on, we'll change to\n inheriting from ``django.contrib.auth.AbstractUser``, and then to another model\n if necessary.\n\n4. Create a normal migration to create the table for this::\n\n ./manage.py makemigrations accounts\n\n This migration must be ``0001_initial`` or you will have problems later on,\n as mentioned in the docs for `AUTH_USER_MODEL\n `_.\n\n The migration will also create M2M tables for the M2M fields specified\n on ``AbstractUser`` itself.\n\n5. Create a data migration that will populate these tables from ``auth.User``::\n\n ./manage.py create_custom_user_populate_migration auth.User accounts.User\n\n All the commands to create migrations take arguments like this.\n\n6. Create a schema migration that will alter every FK that points at ``auth.User``\n to point at your model instead::\n\n ./manage.py create_custom_user_schema_migration auth.User accounts.User\n\n7. Create a data migration that will fix up the contenttypes tables::\n\n ./manage.py create_custom_user_contenttypes_migration auth.User accounts.User\n\n8. Change the ``AbstractUser`` import in your models.py to::\n\n from django.contrib.auth.models import AbstractUser\n\n9. Change ``AUTH_USER_MODEL`` to ``\"accounts.User\"`` in your settings.\n\n10. Run ``makemigrations`` again::\n\n ./manage.py makemigrations accounts\n\n This creates a migration that doesn't actually change fields, but is needed\n for Django to think that everything lines up again.\n\n11. Do related changes for admin etc. as described in Django docs:\n https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-django-s-default-user\n\n Simplest version::\n\n # accounts/admin.py\n\n from django.contrib import admin\n from django.contrib.auth.admin import UserAdmin\n from . models import User\n\n admin.site.register(User, UserAdmin)\n\n12. Create a migration that empties the ``auth.User`` table::\n\n ./manage.py create_custom_user_empty_migration auth.User accounts.User\n\n13. Run all the migrations::\n\n ./manage.py migrate\n\n14. Test everything!\n\n Note that all migrations generated are reversible, but before running them\n in reverse you should set AUTH_USER_MODEL back to ``\"auth.User\"``, and you\n will also therefore need to use the\n ``django_custom_user_migration.models.AbstractModel`` as a base class or you\n will get validation errors that prevent migrations from running.\n\n When running Django unit tests, you may have problems when Django attempts\n to run your migrations in a test database. Since your AUTH_USER_MODEL no\n longer points to ``auth.User``, that table won't be created and the\n migrations which expect it to exist will fail.\n\n In the short term, this can be fixed as per this advice:\n http://stackoverflow.com/a/28560805/182604\n\n Long term, this can be fixed by squashing the ``accounts`` migrations up to\n step 12 into a single migration. Use the ``squashmigrations`` command to do\n this, then manually edit it to remove all but the initial ``CreateModel``\n operation. So the migration created should be the same as accounts\n ``0001_initial``, but it will have a ``replaces`` attribute that marks it as\n squashing the others. You may also need to adjust (remove) some of its\n dependencies.\n\n15. Uninstall ``django_custom_user_migration``, and remove it from your\n ``INSTALLED_APPS``, you don't need it any more. The migrations generated\n run without it being installed.\n\n16. You can now deploy these migrations to your production environment and run\n them in the normal way using ``./manage.py migrate``.\n\nYou can now customise your ``User`` model as required in the normal way, using\nmigrations etc. You could even make it inherit from ``AbstractBaseUser`` or some\nother model instead of ``AbstractUser``, provided that you write/generate the\nnecessary data migrations to cope with missing fields, and update your admin and\napplication accordingly.\n\n\nOther notes\n-----------\n\n* Use at own risk, make sure you back up your data first, etc. etc.\n\n* Tested on sqlite and postgres\n\n* If you have other tables with FKs to ``auth.User`` that Django doesn't know\n about, you will have to deal with those manually with a custom migration. (In\n really old Django projects, you might have old tables like 'auth_message'\n kicking around which you'll need to delete).\n\n* Almost everything included in this library is generic regarding the models\n involved, and uses introspection rather than hard-coding things about\n ``auth.User``. The main exception is\n ``django_custom_user_migration.models.AbstractUser``, which is a copy-paste\n job from Django sources.\n\n This means that you may be able to use the code here to migrate other\n swappable models. This has not been tested however.\n\n\n\nHistory\n-------\n\n0.3.0 (2016-04-04)\n------------------\n\n* Fixed crasher on Django 1.9\n\n0.2.0 (2015-08-20)\n------------------\n\n* Fixed Postgres bug with sequences not being set correctly, which\n caused any subsequent inserts to fail.\n\n* Expanded tests to actually test against Postgres\n\n0.1.0 (2015-08-14)\n------------------\n\n* First release on PyPI.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.com/spookylukey/django_custom_user_migration", "keywords": "Django custom user model migration", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django_custom_user_migration", "package_url": "https://pypi.org/project/django_custom_user_migration/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django_custom_user_migration/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.com/spookylukey/django_custom_user_migration" }, "release_url": "https://pypi.org/project/django_custom_user_migration/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "django_custom_user_migration will help you create a migration to using a custom User model with Django", "version": "0.3.0" }, "last_serial": 2044874, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4d96ea1dfda97a5f361732924266891c", "sha256": "6a778796129b1c1ad4d35c81d011b57991d3b17a06cafbb5d6e1bc49ad631d64" }, "downloads": -1, "filename": "django_custom_user_migration-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4d96ea1dfda97a5f361732924266891c", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 16317, "upload_time": "2015-08-18T16:46:06", "url": "https://files.pythonhosted.org/packages/ee/69/9d69eb908d98cfb469f83ee1905ebe1a1e7ff768432731e5a765ac69750b/django_custom_user_migration-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6cd3b076f0e2032c4426ff278803a528", "sha256": "c4fabad5f597a729182757f3984f1c489a7b7f47ca43186c86c242caf89a5dc5" }, "downloads": -1, "filename": "django_custom_user_migration-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6cd3b076f0e2032c4426ff278803a528", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16753, "upload_time": "2015-08-18T16:45:56", "url": "https://files.pythonhosted.org/packages/72/93/179af0213f39eba20672b987e7f1a17ca628579763921ca6ed73879ae972/django_custom_user_migration-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "14eec09f1bb94b6f4bd834e0b17af83e", "sha256": "4075456e532792817abf65e4ea06a93a03d410e0c5a500b93bc3e6609c03496f" }, "downloads": -1, "filename": "django_custom_user_migration-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "14eec09f1bb94b6f4bd834e0b17af83e", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 17144, "upload_time": "2015-08-20T11:46:48", "url": "https://files.pythonhosted.org/packages/19/ad/d202405765911cfb69eadd37889a22617a0dbc9bd3f3b6d4dd7fffa9fd5e/django_custom_user_migration-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "79a32c2cc95fa09a5baeba0288398c5c", "sha256": "cb3d350110ba280a6b93c841449bec6ea08445105648da0514ef9168ae18e4bc" }, "downloads": -1, "filename": "django_custom_user_migration-0.2.0.tar.gz", "has_sig": false, "md5_digest": "79a32c2cc95fa09a5baeba0288398c5c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17714, "upload_time": "2015-08-20T11:46:43", "url": "https://files.pythonhosted.org/packages/ec/29/cd6b8aa7b4c3678e9232b7d625c8845f91b8c19f6d5c8deaf35fb1a5afe7/django_custom_user_migration-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "58bb4dd7b744c824aa6d4884de3e1589", "sha256": "b4eafe0f513544a50c1f9861ad3f0b455064c6d28254891b2db25a6a83bf4eaf" }, "downloads": -1, "filename": "django_custom_user_migration-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "58bb4dd7b744c824aa6d4884de3e1589", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 18259, "upload_time": "2016-04-04T15:28:37", "url": "https://files.pythonhosted.org/packages/ce/eb/91984d46d8eebd4ef244297458bdcff48424234c66dd9f770cfca8a5253c/django_custom_user_migration-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d849a391911f325ad1d91491e936e83a", "sha256": "1f27543ff0fc7700026baefa3968631d189083d38de21398ea60e616f6ac203f" }, "downloads": -1, "filename": "django_custom_user_migration-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d849a391911f325ad1d91491e936e83a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18494, "upload_time": "2016-04-04T15:26:40", "url": "https://files.pythonhosted.org/packages/c7/6a/0059f0bf5416b66a827fd83d7e725a938a35fc0835e6d075bbe308019651/django_custom_user_migration-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "58bb4dd7b744c824aa6d4884de3e1589", "sha256": "b4eafe0f513544a50c1f9861ad3f0b455064c6d28254891b2db25a6a83bf4eaf" }, "downloads": -1, "filename": "django_custom_user_migration-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "58bb4dd7b744c824aa6d4884de3e1589", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 18259, "upload_time": "2016-04-04T15:28:37", "url": "https://files.pythonhosted.org/packages/ce/eb/91984d46d8eebd4ef244297458bdcff48424234c66dd9f770cfca8a5253c/django_custom_user_migration-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d849a391911f325ad1d91491e936e83a", "sha256": "1f27543ff0fc7700026baefa3968631d189083d38de21398ea60e616f6ac203f" }, "downloads": -1, "filename": "django_custom_user_migration-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d849a391911f325ad1d91491e936e83a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18494, "upload_time": "2016-04-04T15:26:40", "url": "https://files.pythonhosted.org/packages/c7/6a/0059f0bf5416b66a827fd83d7e725a938a35fc0835e6d075bbe308019651/django_custom_user_migration-0.3.0.tar.gz" } ] }