Declare a model field the same as Django's password

Looking at my Db schema it says it is a varchar(128). How do I declare the same in my model?

password = models.?(?)

This is for an API not a user, but something long will do for passwords.

I know that you can use a TextField for long strings, but can you specify a max length with that?

If you look at the source for the password field in the AbstractBaseUser model (django.contrib.auth.base_user) , you’ll see the password field defined as:

password = models.CharField(_(‘password’), max_length=128)

A TextField does not enforce the max_length parameter.

A CharField does enforce max_length, but the actual max value depends upon the database being used. (For Postgresql, the limit is 1GB, which is also the limit for a TextField, and according to the docs, there are no performance differences between the two.)

1 Like