php artisan migration使用SQLite时抛出未定义的属性:stdClass :: $ migration

时间:2019-04-03 21:35:41

标签: php laravel sqlite lumen

运行php artisan migrate会抛出Undefined property: stdClass::$migration,导致不会创建任何表。

我正在使用sqlite。我的.env仅具有:DB_CONNECTION=sqlite。 我创建了一个config/database.php,其中包含:

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

我有两列的简单迁移。

到目前为止,我已经尝试了从创建新的composer项目到重新安装PHP的所有操作。

完整例外:

 () 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

1 个答案:

答案 0 :(得分:1)

事实证明,当您使用SQLite时,您的config/database.php文件需要稍微复杂一些。具体来说,我需要添加 'migrations' => 'migrations' ,这(经过数小时的搜索)解决了该问题。我的database.php文件现在看起来像这样:

        <?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'
    ];