Fixed IntegrityError caused by primary key not being unique