<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply(self):
 """ Applies all migrations that have been added. Note that some migrations depend on others, so you might end up running more than one. """

        if self.__closed:
            raise MigrationSessionError("Can't apply applied session")
        try:
            while self._to_apply:
                self.__apply(migration=self._to_apply.pop(0))
        except:
            raise
        finally:
            self.__closed = True