which is max size of 'max_length' in djang

2019-03-14 06:07发布

问题:

this is my model:

class Position(models.Model):
    map = models.ForeignKey(Map,primary_key=True)
    #members=models.CharField(max_length=200)
    LatLng = models.CharField(max_length=40000)
    infowindow = models.CharField(max_length=40000)

but it can't run ..

thanks

回答1:

That depends on the database backend. The Django DB Docs will tell you, that max_length=255 is guaranteed to work always.

If you need something of the amount you've specified in your question, I'd suggest to use a TextField.



回答2:

use TextField instead

infowindow = models.TextField()


回答3:

It depends on the backend database. If you use MySQL 5.6 then there is no a limit of 65,535. If you are using above that then it will allow for 1024 also but not beyond that.

class Demo(models.Model):
    max_test = models.CharField(max_length=1024)

I ran above on MySQL 5.7



标签: django max