I hate to bring the conversation to a dark place, but there's no way to answer this without going into the tragic back story told to Mike Mozart by his late friend Joe Ranft, the head of writing for Pixar and Toy Story, regarding Andy's family. Mike Mozart recounted the story to the host of the SuperCarlinBrothers YouTube channel. The entire story can be found on CBR.com
It turns out the name "Andy" written underneath Woody's foot actually refers to Andy Sr., the father of the child Andy from the first three Toy Story films. It's revealed that Andy Sr., who doesn't appear in any of the films, contracted polio as a child, so all his belongings were burned for safety. However, he managed to save three toys, locking them away in a trunk: Woody, Mr. Potato Head and Slinky Dog. Andy Sr. lived to be an adult, marrying Molly and fathering their son Andy Jr.
As polio can be known to do, it struck again later in Andy Sr.'s life, forcing Andy and his family to move back to his parents' house, where he eventually passed away. Before he died, however, he managed to introduce his son to the trunk that contained his old toys. Sometime after the funeral, Andy Jr. opened up the trunk, finding Woody, Mr. Potato Head and Slinky.
Well, when Andy Jr. opened the trunk, the toys didn't actually realize this was a different Andy. They assumed Andy Jr. was the same boy that was forced to lock them away decades prior.
Confirming Mozart's account, the intro to the first Toy Story indicates Andy Jr. looks a lot like Andy Sr. did as a kid, as evident in pictures hanging on the wall that show a similar-looking child, wearing glasses. The film takes place shortly after the death of Andy Sr.
The SuperCarlinBros video can be found here.