Changes between Initial Version and Version 1 of Ticket #25313, comment 24


Ignore:
Timestamp:
Apr 12, 2021, 3:39:48 PM (4 years ago)
Author:
Johannes Wilm

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25313, comment 24

    initial v1  
    3030}}}
    3131
    32 4. Edit the migration with a name starting with "0001" of this app.
     324. Set this new model as the default user model in the settings.py file by adding: `AUTH_USER_MODEL = "user.User"`.
     33
     345. Edit the migration with a name starting with "0001" of this app.
    3335
    3436Under "operations" paste the following as the first item:
     
    7476(The exact code to use here will likely change over time with newer versions of Django. You can find the current code by creating a new app temporarily, add the User model to it and then look at the migration file `./manage.py makemigrations` produces.)
    7577
    76 5. Create a new data migration to the user app by typing: `./manage.py makemigrations --empty user`
     786. Create a new data migration to the user app by typing: `./manage.py makemigrations --empty user`
    7779
    78 6. Edit the newly created migration:
     807. Edit the newly created migration:
    7981 
    8082Under "operations" add `migrations.RunPython(change_user_type),`
     
    9496}}}
    9597
    96 7. You can now migrate to the custom user model by running `./manage.py migrate`. This should always work, however, it will do so in two different ways depending on whether it is run on an existing or a new instance:
     988. You can now migrate to the custom user model by running `./manage.py migrate`. This should always work, however, it will do so in two different ways depending on whether it is run on an existing or a new instance:
    9799
    98100* On a new instance, the new user model will be created in migration 0001. The last migration will have no effect.
     
    100102* On an existing instance, the migration 0001 will be ignored as the system has already previously applied migration 0001 and will therefore now ignore it. Instead the last migration will have the effect of change the app of the user model.
    101103
    102 8. Now, you should be able to make changes to your users.User model and run makemigrations / migrate as needed. For example, as a first step, you may wish to rename the auth_user table to something in your users app's namespace. You can do so by removing db_table from your User model, so it looks like this:
     1049. Now, you should be able to make changes to your users.User model and run makemigrations / migrate as needed. For example, as a first step, you may wish to rename the auth_user table to something in your users app's namespace. You can do so by removing db_table from your User model, so it looks like this:
    103105
    104106{{{
     
    116118Please let me know if this works for you - especially with other databases.
    117119
    118 [1] https://www.caktusgroup.com/blog/2019/04/26/how-switch-custom-django-user-model-mid-project/ with mo
     120[1] https://www.caktusgroup.com/blog/2019/04/26/how-switch-custom-django-user-model-mid-project/
Back to Top