Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am getting the above mentioned warning

data truncated for column 'username' at row 1

I am getting this for my model "suserprofile" with "username" as my first listed field in the model

I checked max_length option which is not the problem for me, if I change the order of my fields in the my model(changed "email_id" field to the first in list of the model),then I am getting the warning replacing 'username' with whatever field I mentioned first(in this case email_id) in the model.

I am not getting this warning when running syncdb but getting warning only when I am trying to save a new object in my model("suserprofile") in my views.py file using django by actually running the local browser. I am not understanding why is it happenning

edit:

my model:

class SUserProfile(models.Model):
    email_id            = models.EmailField(max_length=30)
    username      = models.CharField(max_length=50,blank=True)  
    first_name          = models.CharField(max_length=30)
    last_name           = models.CharField(max_length=30)

my view

from django.allauth.models import SocialAccount
def profileview(request):
    user=request.user   
    if user.is_authenticated:
        a=SocialAccount.objects.filter(user=user)   
        try:    
            f=a.get(provider='facebook')
        except:
            f=None
    if f:
        fusername=f.get_provider_account    
        fdata=f.extra_data 
        ffirst_name=fdata['first_name']     
        flast_name=fdata['last_name']
        femail=fdata.get('email')
        try: 
            old_user=SUserProfile.objects.get(email_id=femail)
        except:
            new_user=SUserProfile( 
            username=fusername,
            email_id=femail,
            first_name=ffirst_name,
            last_name=flast_name,)
            new_user.save() 

warning details I'm getting when running the browser:

 Exception Type:    Warning

 Exception Value:   Data truncated for column 'email_id' at row 1

 Exception Location:/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py in _warning_check, line 92

Traceback Switch to copy-and-paste view

usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response

       response = callback(request, *callback_args, **callback_kwargs)

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py in _wrapped_view

       return view_func(request, *args, **kwargs)

...

▶ Local vars
/home/varun/webops/mysite/allauth/account/views.py in profileview

       new_user.save()

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/db/models/base.py in save

self.save_base(using=using, force_insert=force_insert, force_update=force_update)

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/db/models/base.py in save_base

result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py in _insert

       return insert_query(self.model, objs, fields, **kwargs)

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/db/models/query.py in insert_query

    return query.get_compiler(using=using).execute_sql(return_id)

...

 ▶ Local vars
 /usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py in execute_sql

    cursor.execute(sql, params)

...

 ▶ Local vars
 /usr/local/lib/python2.7/dist-packages/django/db/backends/util.py in execute

    return self.cursor.execute(sql, params)

...

▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py in execute

    return self.cursor.execute(query, args)

...

▶ Local vars
/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py in execute

    if not self._defer_warnings: self._warning_check()

...

▶ Local vars
/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py in _warning_check

     warn(w[-1], self.Warning, 3)

...

▶ Local vars 
share|improve this question

3 Answers

Could you please show us your model and the code that throws the exception ? Only showing the error does not helps us to understand the problem.

Regards.

share|improve this answer
I edited the question ,please check now – user2323800 Jun 18 at 20:54

check the column format and length. i got same error when inserting string data with 20 char in varchar column with 10 in length.

share|improve this answer

syncDB will not overwrite existing table/column definitions. So if you've already checked to make sure the lengths in your file are correct, you may want to check that you have remade your tables - you need to drop and recreate them in order for the updated column definitions to be put in place (I've made this error a couple of times myself)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.