The Django documentation makes it clear that FileField takes an optional argument to change the length of the varchar column used to store the file link (file name).
Taken from the Django documentation here :
FileField instances are created in your database as varchar columns with a maximum default length of 100 characters. As in other fields, you can change the maximum length using the max_length argument.
To use this max_length parameter, you simply add the parameter to the declaration of the model field, for example:
class File(models.Model): Record = models.ForeignKey(Records) Title = models.CharField(max_length=255, blank=False) File = models.FileField(upload_to='files/Records', blank=False, max_length=500) Upload_date = models.DateTimeField(auto_now_add=True) def __unicode__(self): return self.Title
The Max_length FileField provided by Django is applied at the database level. When you make changes to the model definition that needs to be done at the database level, you may find that you must use synchronization or migration to make this change to the database. Simply changing the max_length parameter in the model definition will have no effect unless you migrate your database to reflect this change as well.
In this particular case, the varchar columns that represent the reference file name to the file stored in FileField must be updated to allow longer file names. Make sure that you have performed the necessary database maintenance to ensure that your model fields are accurately represented in your database. More information on migrations can be found here .
Mrhwick
source share