Opened 12 years ago

Closed 10 years ago

#18959 closed Cleanup/optimization (duplicate)

Error message for table names > 50 characters is very poor.

Reported by: Steve Lacy Owned by: ANUBHAV JOSHI
Component: contrib.auth Version: dev
Severity: Normal Keywords: permission
Cc: charette.s@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you try to create a model with a table name > 50 characters (and you've enabled django.contrib.auth) then you get a very poor error message when running syncdb.

For example:

env src/tmp/qdel$ python ./ syncdb
Creating tables ...
Traceback (most recent call last):
  File "./", line 10, in <module>
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 443, in execute_from_command_line
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 382, in execute
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/commands/", line 110, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/core/management/", line 189, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/dispatch/", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/contrib/auth/management/", line 54, in create_permissions
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/models/", line 140, in bulk_create
    return self.get_query_set().bulk_create(*args, **kwargs)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/models/", line 416, in bulk_create
    self.model._base_manager._insert(objs_without_pk, fields=[f for f in fields if not isinstance(f, AutoField)], using=self.db)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/models/", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/models/", line 1576, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/models/sql/", line 910, in execute_sql
    cursor.execute(sql, params)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/backends/", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: value too long for type character varying(50)

  • Doesn't tell me which model
  • Doesn't say "generated table name is too long"
  • Works if django.contrib.auth isn't in INSTALLED_APPS, fails otherwise.
  • Can fail if model name < 50 characters when the app name is long. (since table name is concatenation of app & model class names)

I'd guess that the solution is to catch the DatabaseError in contrib/auth/management/ create_permissions() and log some useful message there then re-raise.

Change History (10)

comment:1 by Simon Charette, 12 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #17763.

comment:2 by Simon Charette, 12 years ago

Keywords: permission added
Resolution: duplicate
Status: closedreopened
Triage Stage: UnreviewedDesign decision needed
Version: 1.4master

After a second thought I think it might be worth it to display a more meaningful error message, as proposed, until #17763 is fixed since it might take a while for native migration to land.

I agree that the actual error message is quite confusing, it wouldn't hurt to explain the limitation.

Re-opening as DDN.

comment:3 by Simon Charette, 12 years ago

Cc: charette.s@… added

comment:4 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:5 by Aymeric Augustin, 11 years ago

Triage Stage: Design decision neededAccepted

comment:6 by Claude Paroz, 11 years ago

Type: UncategorizedCleanup/optimization

comment:7 by rasca, 11 years ago

Related to #18866 that tracks the verbose_name errors

Last edited 11 years ago by rasca (previous) (diff)

comment:8 by ANUBHAV JOSHI, 10 years ago

As I have understood it worksforme or else if someone can help me reproduce the problem/error if I am wrong, then it would be very helpful.

comment:9 by ANUBHAV JOSHI, 10 years ago

Owner: changed from nobody to ANUBHAV JOSHI
Status: newassigned

comment:10 by Tim Graham, 10 years ago

Resolution: duplicate
Status: assignedclosed

I tried to reproduce this, but I think it's actually a duplicate of #18866. The column is limited to 50 characters, but it's based on the verbose_name which is now validated for length < 39 so the permission name won't be too long.

Note: See TracTickets for help on using tickets.
Back to Top