urbanplatform / django-keycloak-auth

Middleware to allow authorization using Keycloak and Django for django-rest-framework (DRF). This package should only be used in projects starting from scratch, since it overrides the users' management.
MIT License
32 stars 14 forks source link

Databse migration error: ValueError: Related model 'django_keycloak.keycloakuserautoid' cannot be resolved #26

Closed Wissperwind closed 2 years ago

Wissperwind commented 2 years ago

Hi, I added this library to settings.py like described. Afterwards I tried to execute migrate with a brand new sqlite database. But it does not work.

 Applying django_keycloak.0001_initial... OK
 Applying admin.0001_initial...Traceback (most recent call last):
Wissperwind commented 2 years ago

A workaround is to migrate django_keycloak first, and than migrate the rest.

rjvitorino commented 2 years ago

@Wissperwind indeed, the instructions are the following:

To apply the database migrations, you need to run the migrate command python manage.py migrate django_keycloak and then python manage.py migrate. You should see something like this:

Operations to perform:
  Apply all migrations: django_keycloak
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying django_keycloak.0001_initial... OK
  Applying django_keycloak.0002_auto_20210209_1503... OK
  Applying django_keycloak.0003_auto_20210406_1426... OK
  Applying django_keycloak.0004_keycloakuserautoid... OK
  Applying django_keycloak.0005_auto_20211231_1702... OK

and

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_keycloak, easy_thumbnails, filer, sessions
Running migrations:
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying easy_thumbnails.0001_initial... OK
  Applying easy_thumbnails.0002_thumbnaildimensions... OK
  Applying filer.0001_initial... OK
  Applying filer.0002_auto_20150606_2003... OK
  Applying filer.0003_thumbnailoption... OK
  Applying filer.0004_auto_20160328_1434... OK
  Applying filer.0005_auto_20160623_1425... OK
  Applying filer.0006_auto_20160623_1627... OK
  Applying filer.0007_auto_20161016_1055... OK
  Applying filer.0008_auto_20171117_1313... OK
  Applying filer.0009_auto_20171220_1635... OK
  Applying filer.0010_auto_20180414_2058... OK
  Applying filer.0011_auto_20190418_0137... OK
  Applying filer.0012_file_mime_type... OK
  Applying filer.0013_image_width_height_to_float... OK
  Applying filer.0014_folder_permission_choices... OK
  Applying sessions.0001_initial... OK

It's necessary to run the migrations in two different steps because we must ensure that the django_keycloak migrations run before all other migrations since they depend on them.

NOTE: when running the migrate command for the first time, for django_keycloak, an error related to the admin_interface package may appear. Then, please comment on the 'admin_interface' entry in the INSTALLED_APPS variable in your settings.py file. After migrating the remaining apps, uncomment this line and run migrate again to run the migrations for the admin_interface app. This should go to the README, we'll improve it soon /cc @moritz89

talesmm14 commented 11 months ago

I have the same problem, when performing migrations only from django_keycloak and this is returned:

$ python manage.py migrate django_keycloak

Operations to perform: Apply all migrations: django_keycloak Running migrations: Applying contenttypes.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0001_initial... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying django_keycloak.0001_redo_migrations_0001to0005... OK