Django error message: [“’on’ value must be either True or False.”]

This error occurs in multiple use cases, the following is one use cases which i faced, The usecase is when you use custom user model, and you are creating the migrations from the beginning on a new database, Django will not allow createsuperuser on the custom model. You can follow this simple solution to solve it. Hope this helps.

If you get this error in Django when you try to create super using using python createsuperuser because you are using a custom user model derived from AbstractUser class. The solution is pretty simple

  1. Passwords are encrypted in django, so you should create the password in the right way
  2. You need to create a user in the custom_model table with the generated password in step 1

Lets say you have custom user model derived from AbstractUser as follows

class User(AbstractUser):

    id = models.BigAutoField(primary_key=True)
    user_uuid = models.UUIDField(default=uuid.uuid1())
    full_name = models.CharField(max_length=200,default='')

    email = models.CharField(max_length=200,default='')
    email_last_verified_on = models.DateTimeField(blank=True,null=True)

Django Password generating algorithm is really cool and its abstracted in auth.hasher

>>> from django.contrib.auth.hashers import make_password
>>> print( make_password('password') )
>>> pbkdf2_sha256$216000$NgqlI63iNctd$t/J2yU91o6ZWCkb0BUOOmk5uTRKT1eTZ5TTbHfuYHec=

You take the password in the last line till =

and construct a mysql insert query according to your custom_model_user_table and insert in the mysql

make sure if you are using uuid as a field, generate a uuid and make sure the column value of the uuid is not null otherwise it would throw error as blank uuid during your execution.

Now you are good to go. Hope the solution solved your problem.