Laravel 8 迁移:DB:unprepared 无法在共享托管服务器上运行
Laravel 8 migration: DB:unprepared is not working on shared hosting server
我的迁移在本地服务器上按预期工作,但是当我尝试在实时共享托管服务器上部署我的项目并使用 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),
Object(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');
}
我不确定这里哪里出了问题或者在这种情况下我必须做什么?
我可能有失偏颇,但我会给你一个你不想听到的答案,如果是真的。
您提到了共享托管,当我在托管行业工作了一段时间后,当我看到您的代码时,它真的让我印象深刻。通常,共享主机提供商根本不允许您使用存储的 procedures/functions。我还没有遇到允许它的人。
这只是共享托管服务提供商通常不提供的东西,需要 VPS 或专用服务器。
我希望我的回答是错误的并且他们确实允许这样做并且您可以解决您的问题,但是您应该简单地在实时聊天中询问您的提供商(如果可能)他们是否允许存储过程。他们很有可能没有。
我的迁移在本地服务器上按预期工作,但是当我尝试在实时共享托管服务器上部署我的项目并使用 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),
Object(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');
}
我不确定这里哪里出了问题或者在这种情况下我必须做什么?
我可能有失偏颇,但我会给你一个你不想听到的答案,如果是真的。
您提到了共享托管,当我在托管行业工作了一段时间后,当我看到您的代码时,它真的让我印象深刻。通常,共享主机提供商根本不允许您使用存储的 procedures/functions。我还没有遇到允许它的人。
这只是共享托管服务提供商通常不提供的东西,需要 VPS 或专用服务器。
我希望我的回答是错误的并且他们确实允许这样做并且您可以解决您的问题,但是您应该简单地在实时聊天中询问您的提供商(如果可能)他们是否允许存储过程。他们很有可能没有。