Search code examples
mysqldjangosqlitedjango-migrationsdjango-4.0

1054, "Unknown column" exception upon adding nonexisting field in Django 4.0


I have struck upon a problem of adding additional field. I want it to be boolean, but it doesn't actually matter which type the field will be, because I also tried to create an integer field instead of boolean with getting the same exception.

The exception I get is:

django.db.utils.OperationalError: (1054, "Unknown column 'salary_profile.confirmation_link_sent' in 'field list'")

And here is the model I am talking about with the field already added in the last line:

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    birth_date = models.DateField(null=True)
    employment_date = models.DateField(null=True)
    position = models.ForeignKey('Position', on_delete=models.PROTECT, null=True)
    attestation_date = models.DateField(blank=True, null=True)
    dismiss_date = models.DateField(blank=True, null=True)
    photo = models.ImageField(blank=True, null=True, upload_to=user_directory_path)
    email_is_confirmed = models.BooleanField(default=False)
    confirmation_link_sent = models.BooleanField(default=False)

This problem encountered both in sqlite and mysql.

So far the only answers to the problem I found on the internet were "to delete the whole base and start again", which to put it lightly - ridiculous, but also adding this field manually in the database itself. But I hardly see it as a solution because imagine I have to add 20 of such fields tomorrow, I will have to do those manual additions as well?

And I must add that many answers are getting back to django 1.7 and such, refering to the command syncdb which does no longer exist.

The problem is strange all in itself, because it says to me that "this field doesn't exist". Well of course it doesn't, because I want to add it in the first place.
What shall I do?

And if it matters: any other model works fine if I add this field there. So I bet if you try to replicate the problem, you will make migrations without encountering any troubles.

I think, I need to add additional information regarding the issue. Tell me what should I bring to the table.


Solution

  • Thank you. I made a request to the database in forms.py. In the middle of the traceback, he pointed to this form in which the request was. This problem was solved.