Search code examples
phplaravelsqlitelumen

Undefined property: stdClass::$migration when using SQLite (php artisan migrate)


Running php artisan migrate throws Undefined property: stdClass::$migration, causing no tables to be created.

I am using sqlite. My .env simply has: DB_CONNECTION=sqlite. I created a config/database.php which contains:

    'connections' => [
        'sqlite' => [
            'driver' => 'sqlite',
            'database' => storage_path('database.sqlite'), // Make sure this file exists.
            'prefix' => '',
        ],
    ],

I have a simple migration with two columns.

So far I have tried everything from creating a new composer project to reinstall PHP.

The full exception:

 () at C:\Development\Repositories\phpchat\vendor\illuminate\database\Query\Builder.php:2360
 Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}() at C:\Development\Repositories\phpchat\vendor\illuminate\database\Query\Builder.php:2360
 Illuminate\Database\Query\Builder->pluckFromObjectColumn() at C:\Development\Repositories\phpchat\vendor\illuminate\database\Query\Builder.php:2332
 Illuminate\Database\Query\Builder->pluck() at C:\Development\Repositories\phpchat\vendor\illuminate\database\Migrations\DatabaseMigrationRepository.php:53
 Illuminate\Database\Migrations\DatabaseMigrationRepository->getRan() at C:\Development\Repositories\phpchat\vendor\illuminate\database\Migrations\Migrator.php:90
 Illuminate\Database\Migrations\Migrator->run() at C:\Development\Repositories\phpchat\vendor\illuminate\database\Console\Migrations\MigrateCommand.php:71
 Illuminate\Database\Console\Migrations\MigrateCommand->handle() at n/a:n/a
 call_user_func_array() at C:\Development\Repositories\phpchat\vendor\illuminate\container\BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at C:\Development\Repositories\phpchat\vendor\illuminate\container\BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at C:\Development\Repositories\phpchat\vendor\illuminate\container\BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at C:\Development\Repositories\phpchat\vendor\illuminate\container\Container.php:580
 Illuminate\Container\Container->call() at C:\Development\Repositories\phpchat\vendor\illuminate\console\Command.php:183
 Illuminate\Console\Command->execute() at C:\Development\Repositories\phpchat\vendor\symfony\console\Command\Command.php:255
 Symfony\Component\Console\Command\Command->run() at C:\Development\Repositories\phpchat\vendor\illuminate\console\Command.php:170
 Illuminate\Console\Command->run() at C:\Development\Repositories\phpchat\vendor\symfony\console\Application.php:908
 Symfony\Component\Console\Application->doRunCommand() at C:\Development\Repositories\phpchat\vendor\symfony\console\Application.php:269
 Symfony\Component\Console\Application->doRun() at C:\Development\Repositories\phpchat\vendor\symfony\console\Application.php:145
 Symfony\Component\Console\Application->run() at C:\Development\Repositories\phpchat\vendor\illuminate\console\Application.php:90
 Illuminate\Console\Application->run() at C:\Development\Repositories\phpchat\vendor\laravel\lumen-framework\src\Console\Kernel.php:115
 Laravel\Lumen\Console\Kernel->handle() at C:\Development\Repositories\phpchat\artisan:35

Solution

  • It turns out that when you are using SQLite, your config/database.php file needs to be slightly more elaborate. Specifically, I needed to add 'migrations' => 'migrations', which (after hours of searching) solved the problem. My database.php file now looks like this:

            <?php
    
        // Adapted from here to use SQLite: https://github.com/laravel/laravel/blob/master/config/database.php
        return [
            'default' => env('DB_CONNECTION', 'sqlite'),
            'connections' => [
                'sqlite' => [
                    'driver' => 'sqlite',
                    'database' => storage_path('database.sqlite'), // Make sure this file exists.
                    'prefix' => '',
                ],
            ],
            'fetch' => PDO::FETCH_CLASS, // Returns DB objects in an array format.
            'migrations' => 'migrations'
        ];