Consider converting
repository
into a TextField
177
178
179class BackupService(models.Model):
180 repository = models.CharField(181 max_length=500,
182 default="",
183 verbose_name=gettext_lazy("Backup repository URL"),
Consider converting
secret
into a TextField
83
84class SupportStatus(models.Model):
85 name = models.CharField(max_length=150)
86 secret = models.CharField(max_length=400) 87 expiry = models.DateTimeField(db_index=True, null=True)
88 in_limits = models.BooleanField(default=True)
89 discoverable = models.BooleanField(default=False)
Description
CharField
highlighted in the issue has a max_length
> 256.
It is recommended to use TextField
for such long fields. CharField
should only be used for smaller strings.
Reasons to fix this:
- More readable and maintainable. Any developer reading the code in the future doesn't have to wonder about the specific
max_length
. - If for some reason, the current
max_length
needs to be increased, you'd need to create a new database migration to facilitate this change.
Not Preferred:
class MyModel(models.Model):
my_field = models.CharField(max_length=1000)
Preffered:
class MyModel(models.Model):
my_field = models.TextField()