I am trying to use a datepicker for the date of in my forms, i decided to use he input type date which is supported by most some browsers. i keep getting this error anytime i try to create super user or migrate. I have removed my migrations for the app and added them back with python manage.py makemigrations
but the problem still persists. i do not want to wipe out the database, i have tried this with postgres(local) and mysql(production) and the error is the same.
This is the traceback error.
Traceback (most recent call last):
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/cursors.py", line 163, in execute
result = self._query(query)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 505, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 724, in _read_query_result
result.read()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 1069, in read
first_packet = self.connection._read_packet()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 676, in _read_packet
packet.raise_for_error()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/protocol.py", line 223, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1048, "Column 'dob' cannot be null")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 189, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/models.py", line 157, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/models.py", line 140, in _create_user
user.save(using=self._db)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 67, in save
super().save(*args, **kwargs)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 751, in save
force_update=force_update, update_fields=update_fields)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 800, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 179, in send
for receiver in self._live_receivers(sender)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 179, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/navararl/repositories/health/aview/core/signals.py", line 10, in update_profile_signal
Profile.objects.create(user=instance)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "/home/navararl/repositories/health/aview/core/models.py", line 38, in save
super(Profile, self).save(*args, **kw)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 67, in save
super().save(*args, **kwargs)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 751, in save
force_update=force_update, update_fields=update_fields)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 789, in save_base
force_update, using, update_fields,
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 892, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 932, in _do_insert
using=using, raw=raw,
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/query.py", line 1249, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1395, in execute_sql
cursor.execute(sql, params)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/sentry_sdk/integrations/django/__init__.py", line 489, in execute
return real_execute(self, sql, params)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/cursors.py", line 163, in execute
result = self._query(query)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 505, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 724, in _read_query_result
result.read()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 1069, in read
first_packet = self.connection._read_packet()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 676, in _read_packet
packet.raise_for_error()
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/protocol.py", line 223, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/navararl/virtualenv/repositories/health/3.7/lib/python3.7/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.IntegrityError: (1048, "Column 'dob' cannot be null")
models.py
class Profile(AbstractBaseUser):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
last_name = models.CharField(max_length=100, blank=True)
first_name = models.CharField(max_length=100, blank=True)
middle_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
next_of_kin = models.CharField(max_length=100, blank=True)
dob = models.DateField(max_length=10, blank=True,null=True)
state = models.CharField(max_length=100, blank=True)
password = models.CharField(max_length=100, blank=True)
email = models.EmailField(max_length=150)
signup_confirmation = models.BooleanField(default=False)
address = models.CharField(max_length=255, null=True)
country = models.CharField(max_length=255, null=True)
phonenumber = models.CharField(max_length=20, null=True)
appointment_with = models.ManyToManyField(User, related_name='appontment_with', blank=True)
slug = models.SlugField(max_length=200, null=True)
USERNAME_FIELD ='user'
def save(self, *args, **kw):
self.slug = slugify(f"{self.last_name}-{self.first_name}")
super(Profile, self).save(*args, **kw)
def __str__(self):
return self.user.username
def get_hospitals(self):
return self.hospitals.all()
@property
def get_fullname(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s %s' % (self.first_name, self.last_name, self.middle_name)
return full_name.strip()
forms.py
class PatientForm(UserCreationForm):
first_name = forms.CharField(max_length=100, help_text='First Name')
last_name = forms.CharField(max_length=100, help_text='Last Name')
middle_name = forms.CharField(max_length=100, help_text='Middle Name')
address = forms.CharField(max_length=100, help_text='address')
next_of_kin = forms.CharField(max_length=100, help_text='Next of kin')
dob = forms.DateField(help_text='Date of birth',
widget=forms.widgets.DateInput(attrs={'type': 'date'}))