Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:21:55+00:00 2026-06-12T11:21:55+00:00

I am using django 1.4 and using django model’s filefield to upload some document

  • 0

I am using django 1.4 and using django model’s filefield to upload some document via modelform. I am having following issues:

When I submit form it says:

Data truncated for column 'file_name' at row 1

Following is my model for this:

class App(models.Model):
    user_name=models.CharField(max_length=50)
    email=models.CharField(max_length=50)
    status=models.CharField(max_length=10,choices=APPLICATIONSTATUSCHOICE)
    archived=models.BooleanField()
    mark_spam=models.BooleanField()
    date=models.DateField()
    file_name=models.FileField(upload_to=PATH+"/")
    def getPath(self):
        return PATH
    def __unicode__(self):
        return self.user_name
    def send_email(self):
        pass

Here is the code for model form:

class AppForm(ModelForm):
    class Meta:
     model=App
         exclude=('status','archived','mark_spam')

email=forms.EmailField()

    def save(self,commit=True):
         app=super(AppForm,self).save(commit=False)
     app.status='sent'
         app.save()

Also it is storing file with its original name,can I have it with something unique name as I am from PHP background and in PHP I normally save it like <mysql auto id>.<filextension>, so how can I do it in django. My first impression was that all this will be automatically done via django while it just save it with name of its own choice but I need to save names into db also so want to name them according to my choice. How can it be done and what is problem in my code that is giving above mentioned error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:21:56+00:00Added an answer on June 12, 2026 at 11:21 am

    How long is the file_name you are trying to store?

    By default, FileField instances are created as varchar(100) columns in your database. As with other fields, you can change the maximum length using the max_length argument. That might be resulting the data truncation error.

    Also you can rename your file whatever you want. the upload_to can be a callable that takes the instance and the name of the uploaded file as input and then you can specify the exact name and path you want to store.

    Eg.

    def get_file_name(instance, filename):
        return '/'.join(['blah', instance.user.username, filename])
    
    ...
        file_name=models.FileField(upload_to=get_file_name)
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django model that I'm displaying as a form using a ModelForm.
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
Hi I am using the django model class with some field and a password
Using Django and MySQL. I save the model and no id appears. Seen some
I'm using Django 1.0.2. I've written a ModelForm backed by a Model. This model
I want to make valums/file-uploader run with django upload, using it with model fields
I want to generate a list using my django model say I have these
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
I am using Django 1.3 and trying to use .exists() on a model entry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.