Opened 3 years ago

Closed 20 months ago

#18959 closed Cleanup/optimization (duplicate)

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

Reported by: slacy Owned by: anubhav9042
Component: contrib.auth Version: master
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 Changed 3 years ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #17763.

comment:2 Changed 3 years ago by charettes

  • Keywords permission added
  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Design decision needed
  • Version changed from 1.4 to master

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 Changed 3 years ago by charettes

  • Cc charette.s@… added

comment:4 Changed 3 years ago by aaugustin

  • Status changed from reopened to new

comment:5 Changed 3 years ago by aaugustin

  • Triage Stage changed from Design decision needed to Accepted

comment:6 Changed 3 years ago by claudep

  • Type changed from Uncategorized to Cleanup/optimization

comment:7 Changed 2 years ago by rasca

Related to #18866 that tracks the verbose_name errores

Version 0, edited 2 years ago by rasca (next)

comment:8 Changed 20 months ago by anubhav9042

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 Changed 20 months ago by anubhav9042

  • Owner changed from nobody to anubhav9042
  • Status changed from new to assigned

comment:10 Changed 20 months ago by timo

  • Resolution set to duplicate
  • Status changed from assigned to closed

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