Fix Database Script

to solve the bugs we are having