title: Django field duplicate key when creating account
body: <p>I have a teacher account that I use in my application. Problem now, is that I modified something and I can't figure out the mistake, because when I try to create an account I get this error:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>IntegrityError at /admin/login/
  (1062, "Duplicate entry '' for key 'email'")</code></pre>
  </div>
  </div>
  
  HEre is the traceback:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/
  
  Django Version: 2.0.1
  Python Version: 3.6.2
  Installed Applications:
  ['django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'courses']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  
  Traceback:
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in get_or_create
    487.             return self.get(**lookup), False
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in get
    403.                 self.model._meta.object_name
  
  During handling of the above exception (Student matching query does not exist.), another exception occurred:
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in _execute
    85.                 return self.cursor.execute(sql, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\mysql\base.py" in execute
    71.             return self.cursor.execute(query, args)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in execute
    250.             self.errorhandler(self, exc, value)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\connections.py" in defaulterrorhandler
    50.         raise errorvalue
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in execute
    247.             res = self._query(query)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in _query
    411.         rowcount = self._do_query(q)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in _do_query
    374.         db.query(q)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\connections.py" in query
    292.             _mysql.connection.query(self, query)
  
  The above exception ((1062, "Duplicate entry '' for key 'email'")) was the direct cause of the following exception:
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\core\handlers\exception.py" in inner
    35.             response = get_response(request)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\core\handlers\base.py" in _get_response
    158.                 response = self.process_exception_by_middleware(e, request)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\core\handlers\base.py" in _get_response
    156.                 response = response.render()
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\template\response.py" in render
    106.             self.content = self.rendered_content
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\template\response.py" in rendered_content
    83.         content = template.render(context, self._request)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\template\backends\django.py" in render
    61.             return self.template.render(context)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\template\base.py" in render
    173.                 with context.bind_template(self):
  
  File "c:\users\danny\appdata\local\programs\python\python36-32\Lib\contextlib.py" in __enter__
    81.             return next(self.gen)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\template\context.py" in bind_template
    250.             updates.update(processor(self.request))
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\eve\courses\context_processors.py" in notifications
    5.     if request.user.is_authenticated and request.user.student:
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\utils\functional.py" in inner
    216.         return func(self._wrapped, *args)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\eve\courses\models.py" in &lt;lambda&gt;
    185. User.student = property(lambda p: Student.objects.get_or_create(user=p)[0])
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\manager.py" in manager_method
    82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in get_or_create
    489.             return self._create_object_from_params(lookup, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in _create_object_from_params
    528.             raise e
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in _create_object_from_params
    521.                 obj = self.create(**params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in create
    417.         obj.save(force_insert=True, using=self.db)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\base.py" in save
    729.                        force_update=force_update, update_fields=update_fields)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\base.py" in save_base
    759.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\base.py" in _save_table
    842.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\base.py" in _do_insert
    880.                                using=using, raw=raw)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\manager.py" in manager_method
    82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\query.py" in _insert
    1125.         return query.get_compiler(using=using).execute_sql(return_id)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
    1281.                 cursor.execute(sql, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in execute
    100.             return super().execute(sql, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in execute
    68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
    77.         return executor(sql, params, many, context)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in _execute
    85.                 return self.cursor.execute(sql, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\utils.py" in __exit__
    89.                 raise dj_exc_value.with_traceback(traceback) from exc_value
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\utils.py" in _execute
    85.                 return self.cursor.execute(sql, params)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\django\db\backends\mysql\base.py" in execute
    71.             return self.cursor.execute(query, args)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in execute
    250.             self.errorhandler(self, exc, value)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\connections.py" in defaulterrorhandler
    50.         raise errorvalue
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in execute
    247.             res = self._query(query)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in _query
    411.         rowcount = self._do_query(q)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\cursors.py" in _do_query
    374.         db.query(q)
  
  File "C:\Users\danny\Desktop\Projects\bachelor_thesis\lib\site-packages\MySQLdb\connections.py" in query
    292.             _mysql.connection.query(self, query)
  
  Exception Type: IntegrityError at /admin/login/
  Exception Value: (1062, "Duplicate entry '' for key 'email'")
  </code></pre>
  
  <p>It seems that the error is coming from this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from courses.models import Notification
  
  
  def notifications(request):
      if request.user.is_authenticated and request.user.student:
          student_notifications = Notification.objects.filter(course__student__student_ID=request.user.student.student_ID)
          return {
              'notifications': student_notifications
          }
      return {}</code></pre>
  </div>
  </div>
  </p>