That's why providing security at each school, while a must have is still flawed. Even more flawed is arming teachers... I can easily see a teacher accidently killing an innocent student during one of these events.
Big difference between someone having a gun on them and having the courage and the mental attributes to use in properly in a situation like that... Not easy to kill someone. Strapping on a gun doesn't make you John Wayne or Clint Eastwood.
If there is any solution it will be a combination of things... Some of which are going to curtail (somewhat) existing freedoms when it comes to firearms and what steps can be taken with someone who is thought to have issues when it comes to mental stability.
The idea would never be to systematically arm teachers. Schools should recruit individuals with license to carry and extensive firearm experience to take a job in the school district in any capacity from Aide to Custodial to Administrative. When the lockdown alarm chimes, these individuals do not sit a classroom with the sheltered in place kids and faculty, they look for the perp. These individuals should be engaged with local law enforcement and go through some of the same training as cops and they get paid a significant premium over regular wage to be the guardians of the schools.
No solution is bulletproof, and you never know what type response you are going to get in the face of danger, but inaction is the worst solution of all. And, yes, there are a number of other things that need to be addressed as well, but protecting the schools needs to happen immediately.