I have a field
logo=models.ImageField(upload_to="restaurant_detail/restaurant_detail", help_text = "upload your restaurant logo")
this returns an error,Data truncated for column 'logo' at row 1
so I go ahead to fix it with this statement
alter table my_table modify logo varchar(500)
(I increase the characters.)
This works but everytime I reset the database I have to do this again and when I try and execute the alter statement above and insert data, it still fails with the Data truncated for column 'logo' at row 1 error.
How do I permanently fix this without having to alter the table all the time?
解决方案
Change your field definition to:
logo = models.ImageField(max_length=500, upload_to="restaurant_detail/restaurant_detail", help_text="upload your restaurant logo")
I added the max_length kwarg which tells Django how many chars the field can store and will cause the database field to be created appropriately.