title: Django + MySQL - Admin Site - Add User - OperationalError - SAVEPOINT does not exist
body: <p>We're trying to have a custom User model and behaviors, but then we noticed that even the <strong>default Django installation</strong> has issue when adding a new User via the Django Admin: </p>
  
  <p><img src="https://i.stack.imgur.com/cqgaV.png"></p>
  
  <p>The issue happens even in other Django versions (tried it in Django <strong>1.8</strong>, and w/ the latest one, Django <strong>1.11.3</strong>). Surprisingly, the issue does not happen when using SQLite or PostgreSQL databases. Also, adding user via <code>$./manage.py createuser</code> and programmatically will work. Editing existing uses like the previously created <code>admin</code> superuser via terminal will also work. CRUD mechanisms for Group work as intended, hence only the <code>Add User</code> view is affected. </p>
  
  <p>Possible point of failures include the <strong>Django core</strong> (any version), <strong>MySQL binary</strong> (bundled in XAMPP for Mac, tried various versions also), or the <strong>MySQL-Python</strong> connector (version 1.2.5). Similar issue <a href="https://stackoverflow.com/questions/40905738/django-operationalerror-when-i-try-to-create-user-from-admin">here</a>, using Django <strong>1.10</strong> and MySQL.</p>
  
  <p>Steps to replicate:</p>
  
  <ol>
  <li><p>Install the latest Django version:
  <code>$ pip install django</code></p></li>
  <li><p>Install the Python-MySQL driver:
  <code>$ pip install MySQL-python</code></p></li>
  <li><p>Create a new project:
  <code>$ django-admin.py startproject sandbox</code></p></li>
  <li><p>Create a new database in MySQL and set the db config in <code>settings.py</code></p></li>
  <li><p>Migrate the Django apps' models:
  <code>$ ./manage.py migrate</code></p></li>
  <li><p>Create an <code>admin</code> superuser:
  <code>$ ./manage.py createsuperuser</code></p></li>
  <li><p>Run the Django's bundled server:
  <code>$ ./manage.py runserver</code></p></li>
  <li><p>Go to <code>http://127.0.0.1:8000/admin/login</code>, and login w/ the <code>admin</code> superuser credentials.</p></li>
  <li><p>Try clicking the <strong>Users</strong>' <strong>Add</strong> button. The attached error in screenshot will be triggered.</p></li>
  </ol>
  
  <p>Sample Database Query Logs:</p>
  
  <pre><code>Query   SET NAMES utf8
  Query   set autocommit=1
  Query   SELECT `django_session`.`session_key`, `django_session`.`session_data`, `django_session`.`expire_date` FROM `django_session` WHERE (`django_session`.`session_key` = 'ikql6mk9voxq4g0go9avuvuxxrpvwx9w' AND `django_session`.`expire_date` &gt; '2017-07-10 06:58:15.823513')
  Query   SELECT `auth_user`.`id`, `auth_user`.`password`, `auth_user`.`last_login`, `auth_user`.`is_superuser`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`date_joined` FROM `auth_user` WHERE `auth_user`.`id` = 1
  Query   SAVEPOINT `s123145414516736_x1`
  Query   RELEASE SAVEPOINT `s123145414516736_x1`
  Query   ROLLBACK TO SAVEPOINT `s123145414516736_x1`
  Query   rollback
  Query   set autocommit=1
  Quit
  </code></pre>
  
  <p>It seems that the SAVEPOINT ROLLBACK has been done after the SAVEPOINT RELEASE causing the SAVEPOINT to be missing. Based from <a href="https://dev.mysql.com/doc/refman/5.6/en/savepoint.html" rel="noreferrer">MySQL's SavePoint docs</a>, the natural order seems to be ROLLBACK then RELEASE.</p>
  
  <p>Here's the Traceback messages. No other changes in Django's default <code>settings.py</code> except for the database config/credentials for connecting to MySQL server:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://127.0.0.1:8000/admin/auth/user/add/
  
  Django Version: 1.11.3
  Python Version: 2.7.8
  Installed Applications:
  ['django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles']
  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 "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
    41.             response = get_response(request)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
    187.                 response = self.process_exception_by_middleware(e, request)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
    185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
    551.                 return self.admin_site.admin_view(view)(*args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
    149.                     response = view_func(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
    57.         response = view_func(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
    224.             return view(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
    67.             return bound_func(*args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
    76.             return view(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
    63.                 return func.__get__(self, type(self))(*args2, **kwargs2)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
    67.             return bound_func(*args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
    149.                     response = view_func(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
    63.                 return func.__get__(self, type(self))(*args2, **kwargs2)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/auth/admin.py" in add_view
    103.             return self._add_view(request, form_url, extra_context)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/auth/admin.py" in _add_view
    131.                                                extra_context)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
    1508.         return self.changeform_view(request, None, form_url, extra_context)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
    67.             return bound_func(*args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
    149.                     response = view_func(request, *args, **kwargs)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
    63.                 return func.__get__(self, type(self))(*args2, **kwargs2)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
    1408.             return self._changeform_view(request, object_id, form_url, extra_context)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/transaction.py" in __exit__
    210.                                 connection.savepoint_rollback(sid)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/base/base.py" in savepoint_rollback
    348.         self._savepoint_rollback(sid)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/base/base.py" in _savepoint_rollback
    308.             cursor.execute(self.ops.savepoint_rollback_sql(sid))
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
    80.             return super(CursorDebugWrapper, self).execute(sql, params)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
    65.                 return self.cursor.execute(sql, params)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/utils.py" in __exit__
    94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
    63.                 return self.cursor.execute(sql)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
    101.             return self.cursor.execute(query, args)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/MySQLdb/cursors.py" in execute
    205.             self.errorhandler(self, exc, value)
  
  File "/Users/ranelpadon/.virtualenvs/django__1_11/lib/python2.7/site-packages/MySQLdb/connections.py" in defaulterrorhandler
    36.     raise errorclass, errorvalue
  
  Exception Type: OperationalError at /admin/auth/user/add/
  Exception Value: (1305, 'SAVEPOINT s123145452511232_x1 does not exist')
  </code></pre>