2

I have one Django model field definition like this:

landMark = models.CharField(max_length=50, blank=True)

Can I define the landMark field dynamically so that it is capable of holding a string which has a varying size ?

1
  • landMark can already handle strings of varying size, up to a maximum length of 50 characters. Are you asking how to remove the upper limit entirely? Commented Feb 18, 2017 at 18:44

2 Answers 2

5

In a way, you already have. The field you have declared is capable of storing a string of any length, as long as it does not exceed 50 characters.

Now, if you want to be able to store an unlimited amount of characters, you can also use a TextField. For example:

landMark = models.TextField(blank=True)
Sign up to request clarification or add additional context in comments.

Comments

0

No you can't. The length of string that can be accepted relies on the structure of your database -> you'd have to migrate your database on every max_length change! The solution to your problem would be to simply measure a potential maximum size of variable you'd like to save (here I think about some dev environment). Then set max_length accordingly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.