lazy reference: doesn't provide model user?

后端 未结 9 1325
独厮守ぢ
独厮守ぢ 2020-12-15 06:33

Currently I\'m using Django 1.11 and Python 3.6. I\'m attempting to create a custom user model with a new application that authenticates with LDAP, but i\'m greeted with th

相关标签:
9条回答
  • 2020-12-15 07:05

    Alternatively, you can also try:

    1. Do python manage.py migrate <app_name> on the app that contains the custom user model.
    2. Do python manage.py migrate to apply the rest of the migrations of the app.

    The reason why this works is that you're applying the changes of the new User model first before you applied the rest of the auth model that's built in Django.

    not sure if I explained that right

    0 讨论(0)
  • 2020-12-15 07:07

    This:

    This is caused by your settings.AUTH_USER_MODEL having changed to a model that does not exist when migrations are being computed.

    ... mentioned by @AKX in their answer gave me an idea which worked.

    I did the following:

    1. Do everything to put your custom User model into place. Set AUTH_USER_MODEL in settings.py and update any uses of django.contrib.auth.models.User with your custom user model.
    2. Run python manage.py makemigrations
    3. Undo step 1
    4. Run python manage.py migrate
    5. Redo step 1
    0 讨论(0)
  • 2020-12-15 07:13

    For me helped split on two migration

    1. create new table (without connection between new and old tables and without AUTH_USER_MODEL = 'accounts.User')
    2. add AUTH_USER_MODEL to settings.py and other connections with new table

    But it works for dev/production databases if you want to apply migrations from first in tests or another from scratch database creations you should "compact your migrations", for me it was next steps:

    1. Make a dump of a database (in my case by sqldump)
    2. Cleanup database (especially table django_migrations)
    3. Remove all migrations in your project
    4. Run manage.py makemigrations
    5. Add migration that adds all data inserts from your old migrations
    6. Run manage.py migrate
    7. Remove table django_migrations in your dump (maybe some other django_* tables )
    8. Restore your database from a dump
    0 讨论(0)
提交回复
热议问题