【问题标题】:Laravel 8 migration: DB:unprepared is not working on shared hosting serverLaravel 8 迁移:DB:unprepared 不适用于共享托管服务器
【发布时间】:2021-10-10 06:15:49
【问题描述】:

我的迁移在本地服务器上按预期工作,但是当我尝试在实时共享托管服务器上部署我的项目并使用 php artisan migrate 后,我收到以下错误。

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:692 
688▕         // If an exception occurs when attempting to run a query, we'll format the error
689▕         // message to include the bindings with SQL, which will make this exception a
690▕         // lot more helpful to the developer instead of just the database's errors.
691▕         catch (Exception $e) {
➜ 692▕             throw new QueryException(
693▕                 $query, $this->prepareBindings($bindings), $e
694▕             );
695▕         }
696▕     }

  +7 vendor frames
  8   database/migrations/2021_08_03_215015_create_user_turning_functions_table.php:14
  Illuminate\Support\Facades\Facade::__callStatic("unprepared")

  +21 vendor frames
  30  artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput),

对象(Symfony\Component\Console\Output\ConsoleOutput))

迁移:

public function up()
{
    DB::unprepared("
            CREATE OR REPLACE FUNCTION `get_classes`(subjects VARCHAR(140))
            RETURNS varchar(200)
            BEGIN
            DECLARE classes VARCHAR(48);
            SET classes='something here';
            RETURN classes;
        END");
}

public function down()
{
    DB::unprepared('DROP FUNCTION IF EXISTS get_classes');
}

我不确定我在哪里出错或在这种情况下我必须做什么?

【问题讨论】:

  • 数据库设置一样吗? DB用户是否有权创建函数?
  • 是的,所有其他迁移都正常工作,而视图迁移不起作用,因为它有 DB::unprepared("")
  • 签入app/database.php并设置`'strict'=>false`然后重试
  • @HardikSisodia 本地服务器和托管服务器版本相同吗?
  • @ThânLƯƠNG 你问的是php版本吗?是的,它是一样的

标签: mysql laravel laravel-8 laravel-migrations


【解决方案1】:

我可能会跑题,但我会给你答案,如果是真的,你不想听。

您提到了共享托管,当我在托管行业工作了一段时间后,当我看到您的代码时,它真的很吸引我。通常,共享主机提供商根本不允许您使用存储过程/函数。我还没有遇到过允许的。

这只是共享主机提供商通常不具备的功能,需要 VPS 或专用服务器。

我希望我的回答是错误的,他们确实允许这样做,您可以解决您的问题,但是您应该在实时聊天中(如果可能)询问您的提供商是否允许存储过程。他们很有可能不会。

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 2013-07-18
    • 2012-07-17
    • 1970-01-01
    • 2019-10-24
    • 2016-11-20
    • 2016-11-16
    • 1970-01-01
    相关资源
    最近更新 更多