Something you should do when posting code. Before posing it, create an empty database, run your code there. If it doesn't work, rework it until it does run successfully in an empty database.
You wouldn't give flawed code to your users, don't give it to us either. It just makes it harder for us to help you.