mysql alter强制截断,如何永久修复mysql错误:使用alter table语句截断列的数据?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值