zsoldosp / django-currentuser

Conveniently store reference to request user on thread/db level.
BSD 3-Clause "New" or "Revised" License
157 stars 40 forks source link

Error and Warning on Django V3.2 on Custom User Model Migrations #54

Open ibnshayed opened 3 years ago

ibnshayed commented 3 years ago

According to github's REAEME.md

On Custom User Model

created_by = CurrentUserField()
updated_by = CurrentUserField(on_update=True)

it gives me this error

$ py manage.py makemigrations
SystemCheckError: System check identified some issues:

ERRORS:
authentication.User.created_by: (fields.E304) Reverse accessor for 'authentication.User.created_by' clashes with reverse accessor for 'authentication.User.updated_by'.
        HINT: Add or change a related_name argument to the definition for 'authentication.User.created_by' or 'authentication.User.updated_by'.
authentication.User.updated_by: (fields.E304) Reverse accessor for 'authentication.User.updated_by' clashes with reverse accessor for 'authentication.User.created_by'.
        HINT: Add or change a related_name argument to the definition for 'authentication.User.updated_by' or 'authentication.User.created_by'.

Then I Try to Solve like the following

created_by = CurrentUserField(related_name="+")
updated_by = CurrentUserField(on_update=True, related_name="+")

Then it gives me following warning

$ py manage.py makemigrations
E:\django\venv\lib\site-packages\django_currentuser\db\models\fields.py:57: UserWarning: You passed 
an argument to CurrentUserField that will be ignored. Avoid args and following kwargs: default, null, to.       
  warnings.warn(self.warning)
Migrations for 'authentication':
  authentication\migrations\0001_initial.py
    - Create model User
    - Create model Permission
    - Create model Role
    - Add field role to user
    - Add field updated_by to user

Please help me to fix this warning and errors

ShmuelTreiger commented 2 years ago

Same issue. Can safely ignore for now, since it's just a warning. Commenting to Follow.