1. hakanw
  2. django-email-usernames
  3. Issues
Issue #6 new

query_fix_usertable does not work with postgres, and ignores the Y/N answer

real_gone_guy
created an issue

when fixing the usertable, to adjust username length to 75 through query_fix_usertable(), 2 problems. First, the command doesn't work with postgres, and seconds, the answer (for Y/N) doesn't allow a N and doesn't check the answer.

This is the code I'm using to fix both those problems:

{{{

!python

def query_fix_usertable(sender, app, created_models, verbosity, interactive, **kwargs): model_names = [m.name for m in created_models] if not interactive or app.name != 'django.contrib.auth.models' or "User" not in model_names: return

answer = raw_input(message)
while not answer.lower() in ('y', 'n', 'yes', 'no'):
    answer = raw_input("You need to either decide yes ('y') or no ('n'). Default is no. (y/N): ")

if answer.lower()[0] == 'y':
    try:
        from django.db import connection
        cursor = connection.cursor()
        cursor.execute("ALTER TABLE auth_user MODIFY COLUMN username varchar(75) NOT NULL")
    except:
        #

}}}

Comments (1)

  1. real_gone_guy reporter

    One more time with the code fix, since it didn't all copy:

    def query_fix_usertable(sender, app, created_models, verbosity, interactive, **kwargs):
        model_names = [m.__name__ for m in created_models]
        if not interactive or app.__name__ != 'django.contrib.auth.models' or "User" not in model_names:
            return
    
        answer = raw_input(message)
        while not answer.lower() in ('y', 'n', 'yes', 'no'):
            answer = raw_input("You need to either decide yes ('y') or no ('n'). Default is no. (y/N): ")
    
        if answer.lower()[0] == 'y':
            try:
                from django.db import connection
                cursor = connection.cursor()
                cursor.execute("ALTER TABLE auth_user MODIFY COLUMN username varchar(75) NOT NULL")
            except:
                from django.db import transaction
                connection._rollback()
                cursor.execute('ALTER TABLE auth_user ALTER COLUMN username type varchar(75)')
                transaction.commit_unless_managed()
    
  2. Log in to comment