This should only happen because of missing db:seeds. It could be better prevented with NOT NULL constraints, but that is a riskier change. This will cause 404s to happen instead of 500s until the seed gets run correctly.