【问题标题】:Laravel 8 can't run Artisan::call('migrate', ['--force' => true])Laravel 8 无法运行 Artisan::call('migrate', ['--force' => true])
【发布时间】:2021-06-06 02:04:09
【问题描述】:

我正在 Laravel 8 中创建 Laravel 安装向导,但运行时出现问题

Artisan::call('migrate', ['--force' => true])

当我执行代码时,我收到了这条消息

SQLSTATE[42000]: 语法错误或访问冲突: 1103 Incorrect table name '' (SQL: create table `` (id int unsigned not null auto_increment 主键, migration varchar(191) not null, @ 987654324@ int not null) 默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

我尝试使用php artisan migrate 运行迁移,它运行良好。 我认为问题出在创建migrations 表时,因为我没有任何带有migrationbatch 字段的表

这是我的migrate() 函数

public function migrate()
{
    try {
        Artisan::call('migrate', ['--force' => true]);
    } catch (\Throwable $th) {
        return $this->response(
            "Failed to migrate tables. ".$th->getMessage(),
            'error'
        );
    }

    return $this->seed();
}

这是我的seed() 函数

public function seed()
{
    try {
        Artisan::call('db:seed', ['--force' => true]);
    } catch (\Throwable $th) {
        return $this->response(
            "Failed to seed tables. ".$th->getMessage(),
            'error'
        );
    }

    return $this->response(
        "Successfully migrated and seeded tables.", 
        'success'
    );
}

【问题讨论】:

  • 检查你的迁移文件夹是否有没有表名的文件
  • @Doggo 没有,没有没有表名的文件
  • 尝试在您的config -> database.php 中添加'migrations' => 'migrations'
  • 已经存在
  • 您是否尝试运行php artisan config:cache

标签: php laravel laravel-8


【解决方案1】:

Artisan 命令与您的代码所在的文件夹相关。因此,如果您不在应用程序的根文件夹中,则必须指定迁移文件夹的路径。

Artisan::call('migrate', array('--path' => '../app/database/migrations'));

【讨论】:

    猜你喜欢
    • 2017-08-08
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 2016-09-07
    • 2017-01-07
    • 2020-07-16
    • 2014-08-05
    相关资源
    最近更新 更多