I need to save an object that contains a file and some other data. Although the file is stored on the /media folder, the entity is not saved in the database since saving it triggers an integration error.
django.db.utils.IntegrityError: NOT NULL constraint failed: app_eeg.filename
'filename' was a field I deleted and I already deleted the migrations folder and did the following commands:
python3 manage.py makemigrations app
python3 manage.py migrate app
Models.py
class EEG(models.Model):
file = models.FileField(null=False)
status = models.BooleanField(default=True)
timestamp = models.DateTimeField(auto_now_add=True)
report = models.ForeignKey(Report, verbose_name=('report'), on_delete=models.CASCADE, related_name='%(class)s_report', null=True)
operator = models.ForeignKey(Operator, verbose_name=('operator'), on_delete=models.CASCADE, related_name='%(class)s_operator', null=False)
patient = models.ForeignKey(Patient, verbose_name=('patient'), on_delete=models.CASCADE, related_name='%(class)s_patient', null=False)
How can I fix this error from happening?
CodePudding user response:
Drop the column from the table manually by connecting to the database and execute the SQL statement:
ALTER TABLE app_eeg DROP COLUMN filename;