﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23610	Removing a null constraint can lead to race conditions with migrations	Josh Smeaton	Jacob Walls	"I think a race condition exists when removing a null constraint that doesn't contain a default. This discussion started with regards to #23609. The flow here was changing a column from having a null to having a default:

`IntegerField(null=True) -> IntegerField(default=42)`

And the race condition:

- Deploy migration
- Update App Server 1 code
- App Server 2 tries to write to the table, and gets a write error (since it doesn't yet have the default in its models file)
- Update App Server 2 code

For a write heavy table, this could result in many failed writes.

I think we should be clear, and document, that removing a null on a column should always be done in two steps:

1. Add a default to the column. Deploy migration. Deploy app code.
2. Remove the null and the default from the column. Deploy migration. Deploy app code.

Perhaps there could be a check that ensures that removing a null always requires an existing default to exist."	Cleanup/optimization	closed	Documentation	1.7	Normal	wontfix	migrations		Accepted	1	0	0	0	0	0
