Add user does not have a field for entering the email. How to fix?

I want add user in page /admin/auth/user/add/ but error after add user.
Not have a field for entering the email.



tutor_local-lms-1          | Traceback (most recent call last):
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
tutor_local-lms-1          |     response = get_response(request)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
tutor_local-lms-1          |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/opt/pyenv/versions/3.11.8/lib/python3.11/contextlib.py", line 81, in inner
tutor_local-lms-1          |     return func(*args, **kwds)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/options.py", line 688, in wrapper
tutor_local-lms-1          |     return self.admin_site.admin_view(view)(*args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
tutor_local-lms-1          |     response = view_func(request, *args, **kwargs)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
tutor_local-lms-1          |     response = view_func(request, *args, **kwargs)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/sites.py", line 242, in inner
tutor_local-lms-1          |     return view(request, *args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
tutor_local-lms-1          |     return bound_method(*args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper
tutor_local-lms-1          |     return view(request, *args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
tutor_local-lms-1          |     return bound_method(*args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
tutor_local-lms-1          |     response = view_func(request, *args, **kwargs)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/auth/admin.py", line 119, in add_view
tutor_local-lms-1          |     return self._add_view(request, form_url, extra_context)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/auth/admin.py", line 147, in _add_view
tutor_local-lms-1          |     return super().add_view(request, form_url, extra_context)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1886, in add_view
tutor_local-lms-1          |     return self.changeform_view(request, None, form_url, extra_context)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
tutor_local-lms-1          |     return bound_method(*args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
tutor_local-lms-1          |     response = view_func(request, *args, **kwargs)
tutor_local-lms-1          |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1747, in changeform_view
tutor_local-lms-1          |     return self._changeform_view(request, object_id, form_url, extra_context)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1798, in _changeform_view
tutor_local-lms-1          |     self.save_model(request, new_object, form, not add)
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1227, in save_model
tutor_local-lms-1          |     obj.save()
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/auth/base_user.py", line 76, in save
tutor_local-lms-1          |     super().save(*args, **kwargs)
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save
tutor_local-lms-1          |     self.save_base(
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/base.py", line 877, in save_base
tutor_local-lms-1          |     updated = self._save_table(
tutor_local-lms-1          |               ^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/base.py", line 1020, in _save_table
tutor_local-lms-1          |     results = self._do_insert(
tutor_local-lms-1          |               ^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/base.py", line 1061, in _do_insert
tutor_local-lms-1          |     return manager._insert(
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
tutor_local-lms-1          |     return getattr(self.get_queryset(), name)(*args, **kwargs)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1805, in _insert
tutor_local-lms-1          |     return query.get_compiler(using=using).execute_sql(returning_fields)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
tutor_local-lms-1          |     cursor.execute(sql, params)
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
tutor_local-lms-1          |     return self._execute_with_wrappers(
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
tutor_local-lms-1          |     return executor(sql, params, many, context)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
tutor_local-lms-1          |     with self.db.wrap_database_errors:
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
tutor_local-lms-1          |     raise dj_exc_value.with_traceback(traceback) from exc_value
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
tutor_local-lms-1          |     return self.cursor.execute(sql, params)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/mysql/base.py", line 75, in execute
tutor_local-lms-1          |     return self.cursor.execute(query, args)
tutor_local-lms-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 179, in execute
tutor_local-lms-1          |     res = self._query(mogrified_query)
tutor_local-lms-1          |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 330, in _query
tutor_local-lms-1          |     db.query(q)
tutor_local-lms-1          |   File "/openedx/venv/lib/python3.11/site-packages/MySQLdb/connections.py", line 261, in query
tutor_local-lms-1          |     _mysql.connection.query(self, query)
tutor_local-lms-1          | django.db.utils.IntegrityError: (1062, "Duplicate entry '' for key 'auth_user.email'")

You add the user with username first and then find that user to add email later.
The error occurs because you added a user and then you try to add another user, so both have the same email (empty). To fix it, you must find the existing user with empty email (go to /admin/auth/user/ and sort the user list by email) and update its email.

@Anh_Vu_Nguy_n It working.
image


Thanks.

As far as I’m aware, adding new users via the django interface isn’t generally recommended, I’ve had issues in the past with users created this way so I stopped doing it.
You’d probably be better off using the commandline as detailed here: Local deployment — Tutor documentation
tutor local do createuser --staff --superuser yourusername user@email.com
the staff and superuser switches will only be for admins/authors and can be removed for learners

1 Like

Hi , @joel.edwards Thanks. I can add fistname and lastname in command line or docker exec to mysql for add it?
if i want run .sh for add user?