Spatial structures as a result of a modulational instability are studied in a nonlinear cavity with a photonic crystal. The interaction of the modulated refractive index with the nonlinearity inhibits the instability via the creation of a photonic band gap. A novel mechanism of light localization due to defects and pattern inhibition is also described.