Django Admin Server 500

Hi,

I have a unique constraint set for 1 of my fields in the model.

    class Meta:
        constraints = [
            models.UniqueConstraint(
                Lower('name'),
                name='uniqueName'
            ),
        ]

When I run this locally and try to add a new item with a duplicated name within the admin I get a nice validation error saying the name already exists, but when I push this change to production, instead of getting the nice validation error it just returns server 500 error.

Is this expected? I was hoping that it would work the same way as running locally.

Is there a way to prevent this from happening?

Thanks

There’s always the chance that there’s a different reason that the system is throwing a 500. You need to check the logs on the server to get the stacktrace to identify the root cause. You can waste a lot of time looking in the wrong areas.

Hi, Ken.

It seems to be caused by that setting. If I set debug=True I don’t get the error in Prod. As soon as i switch to debug=False it throws the 500.

I’ll keep investigating

You really shouldn’t jump to that conclusion without looking at the traceback. Changing the debug setting has a number of different effects on how Django operates.

Your first step should always be to gather all relevent information, and the traceback is a big part of that.