Cannot get migration step to execute


I’ve created a migration step for the files_sharing app:

sudo -u www-data ./occ migrations:generate files_sharing 24000
New migration class has been generated to /var/www/nextcloud23-dev/apps/files_sharing/lib/Migration/Version24000Date20220208195521.php

Here’s the class:



namespace OCA\Files_Sharing\Migration;

use Closure;
use OCP\DB\Types;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version24000Date20220208195521 extends SimpleMigrationStep {

         * @param IOutput $output
         * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
         * @param array $options
         * @return null|ISchemaWrapper
        public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
                $schema = $schemaClosure();
                $table = $schema->getTable('share');
                $table->addColumn('password_expiration_time', Types::TIME);
                return $schema;


Now, when I try to execute it, I got:

sudo -u www-data ./occ migrations:execute files_sharing 24000Date20220208195521

In MigrationService.php line 507:

  Migration step 'OCA\Files_Sharing\Migration\Version24000Date20220208195521' is unknown

migrations:execute <app> <version>

Apparently, the issue is that SimpleContainer->resolve() does not find the class:

        public function resolve($name) {
                $baseMsg = 'Could not resolve ' . $name . '!';
                try {
                        $class = new ReflectionClass($name);
                        if ($class->isInstantiable()) {
                                return $this->buildClass($class);
                        } else {
                                throw new QueryException($baseMsg .
                                        ' Class can not be instantiated');
                } catch (ReflectionException $e) {
                        throw new QueryException($baseMsg . ' ' . $e->getMessage());

The $class = new ReflectionClass($name) statement throws a ‘class does not exist’ error: Class OCA\Files_Sharing\Migration\Version24000Date20220208195521 does not exist

Does anyone have an idea what I’ve been doing wrong?



Ok, I’ve received an answer in the chat.

The problem is that “the class isn’t know to composer so you won’t be able to execute it manually”

The solution is to run “composer dump-autoload” from within the app’s composer folder.

And, in the long-term, learn more about composer :slight_smile: