Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransactionManagementError when model has primary_key=True #25

Open
youhongshen opened this issue Aug 11, 2016 · 0 comments
Open

TransactionManagementError when model has primary_key=True #25

youhongshen opened this issue Aug 11, 2016 · 0 comments

Comments

@youhongshen
Copy link

When I tried to add an entry to Zone table, I get the an error message (see below). I have several model classes. It seems like I only get this error if my model has primary_key=True.

model with the problem
class Zone(models.Model):
name = models.CharField(max_length=20, primary_key=True)

def __unicode__(self):
    return '%s' % self.name

error message

Environment:

Request Method: POST
Request URL: http://icbsgps01-dev:8001/admin/inventory/zone/add/

Django Version: 1.8.11
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
'nested_admin',
'rest_framework',
'rest_framework_extensions',
'papriqa.release_manifest',
'papriqa.sw_validation',
'papriqa.alarm_reg',
'papriqa.inventory',
'import_export',
'session_security',
'simple_audit')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'session_security.middleware.SessionSecurityMiddleware',
'simple_audit.middleware.TrackingRequestOnThreadLocalMiddleware')

Traceback:
File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  2.             return self.admin_site.admin_view(view)(_args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  3.                 response = view_func(request, _args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  4.     response = view_func(request, _args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  5.         return view(request, _args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  6.     return self.changeform_view(request, None, form_url, extra_context)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  7.         return bound_func(_args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  8.                 response = view_func(request, _args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  9.             return func.**get**(self, type(self))(_args2, *_kwargs2)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/utils/decorators.py" in inner
  10.                 return func(_args, *_kwargs)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
  11.             self.save_model(request, new_object, form, not add)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
  12.     obj.save()
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/base.py" in save
  13.                    force_update=force_update, update_fields=update_fields)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  14.         updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/base.py" in _save_table
  15.                                   forced_update)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/base.py" in _do_update
  16.         return update_fields is not None or filtered.exists()
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/query.py" in exists
  17.         return self.query.has_results(using=self.db)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/sql/query.py" in has_results
  18.     return compiler.has_results()
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in has_results
  19.     return bool(self.execute_sql(SINGLE))
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  20.         cursor.execute(sql, params)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  21.         return super(CursorDebugWrapper, self).execute(sql, params)
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  22.     self.db.validate_no_broken_transaction()
    
    File "/home/npacadm/joan_env2/lib/python2.7/site-packages/django/db/backends/base/base.py" in validate_no_broken_transaction
  23.             "An error occurred in the current transaction. You can't "
    

Exception Type: TransactionManagementError at /admin/inventory/zone/add/
Exception Value: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant