I'm trying to simulate an integrator circuit in LTspice, but it doesn't work.
By the transfer function, the circuit behaves like an integrator and like a low-pass circuit.
When I input a square wave, the desired input signal should be a triangle wave, but the output that the LTspice shows is a constant saturated 12V signal.
What could be wrong with this simulation? I have attached the simulation images.
By using an additional inverter function, your circuit has positive instead of negative feedback. To make an integrator, you can omit U2 and connect C1 to U1 output.
Initial condition of the integrator however needs special attention. It can be achieved by an explicite .IC statement, using the UIC option in transient simulation or a reset circuit.
The opamp has no DC negative feedback (a resistor parallel with the integrator capacitor) causing its DC gain to be almost 1 million. Then its output will probably be at the positive or negative supply caused by it amplifying its DC input offset voltage 1 million times.