Internal server error when deleting model on production-server

When I’m deleting a company using my Django web-interface on the production-server as a superadministrator, I’m receive a Internal server error 500 as response which is displayed on the screen.
Here is the possible additional error log I received only once

Deleting a company does work locally on my PC and on the test-server.

Delete code backend:
class CompanyDeleteView(GroupRequiredMixin, LoginRequiredMixin, View):
group_required = [u"SuperAdministrator"]

def delete(self, request, **kwargs):
    company_id = kwargs.get('pk')
    if company_id:
        company = shortcuts.get_object_or_404(models.CompanyModel, id=company_id)

        users = []
        admins = []

        for user in company.users.all():
            if helpers.get_user_level(user) in ['SuperAdministrator', 'TechnicalService']:


        for user in users:

        perfotec = models.CompanyModel.objects.get(name='Perfotec')

        for user in admins:

        return http.HttpResponse(json.dumps("success"), content_type="application/json")
    return http.HttpResponseBadRequest()

Javascript code in HTML file:

My first reaction to this is that you haven’t applied one or more migrations in your production system. Your code thinks there’s a model but that model doesn’t exist in the database. (It would be something like GasAnalyserProgramModel in the manager app.)

Do you have an app named manager? Does it define a model named something like GasAnalyserProgramModel? (Or do you have a model with manager_gasanalyserprogrammodel defined as the table name in the Meta class?)

Yes, I have a GasAnalyserProgramModel wich contains a company foreign-key, with on_delete=models.CASCADE. But my CI/CD should have run python migrate so this table would be created.
Maybe it is neccessary to run that command manually? And could I do that in production?

Don’t know. The first thing I’d do is check whatever logs you have from your CI/CD process to see if it even tried to do it, and if it did, if there were any errors.

Something needs to run migrate in production. It doesn’t matter much if it’s your CI/CD or you running it manually. It’s the same command. However, you are going to want to stop and restart your application after it runs.

I’m going to run the migrate command in production because I don’t see it in the CI/CD log.