Laravel 5: 迁移路线 - Artisan::call('migrate', array('--force' => true)) 停止
Laravel 5: Migration-Route - Artisan::call('migrate', array('--force' => true)) stops
我的应用程序中有一个迁移路径,当前输出是:
init migrate:install...done migrate:install
init with tables migrations...
现在它停止了。但是输出应该会继续。路线如下:
Route::get('/migrate', function () {
try {
try {
echo '<br>init migrate:install...';
Artisan::call('migrate:install');
echo 'done migrate:install';
} catch (Exception $e) {
echo 'allready installed';
}
echo '<br>init with tables migrations...';
Artisan::call('migrate', array('--force' => true)); // here it stops via browser
echo 'done with migrations';
echo '<br>clear view cache...';
$cachedViewsDirectory = app('path.storage').'/framework/views/';
if ($handle = opendir($cachedViewsDirectory)) {
while (false !== ($entry = readdir($handle))) {
if(strstr($entry, '.')) continue;
@unlink($cachedViewsDirectory . $entry);
}
closedir($handle);
}
echo 'all view cache cleared';
return redirect()->route('backend::dashboard');
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
});
在访问 Shell 和 运行 迁移时它将起作用:
-bash-4.2$ /opt/plesk/php/5.6/bin/php artisan migrate
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> yes
Migrated: 2016_08_23_194102_import_old_data
Migrated: 2016_08_25_080129_import_old_adresses
Migrated: 2016_08_25_080801_import_oldname_to_accountholder
为什么它在路由中不起作用?
更新
Apache 日志显示 "GET /migrate HTTP/1.0" return 状态 200,因此其 HTTP 正常。
在浏览器开发工具中也没有错误。
更新 2
另外 laravel.log 是空的。调用迁移路由期间没有新条目。
post 错误,打开开发工具 > 网络选项卡,或 apache 错误日志
好的,我知道了 运行。
原始迁移(如果我白痴发布它可能会有用)
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Load data to be imported.
$oldOrders = json_decode(File::get('storage/olddata.json'), TRUE);
// Update.
foreach ($oldOrders as $rawOrder) {
/* @var \App\Order $order */
$order = \App\Order::find(intval($rawOrder['id']));
// Check whether order is payed.
if ($order->isPayed() === FALSE && floatval($rawOrder["payedAmount"]) != 0) {
/* @var \App\Payment $payment */
$payment = new \App\Payment();
$payment->order_id = $order->id;
$payment->amount = $rawOrder["payedAmount"];
$payment->method = $rawOrder["paymentMethod"];
$payment->save();
}
}
}
现在迁移
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Load data to be imported.
$oldOrders = json_decode(File::get(base_path('storage/olddata.json')), TRUE);
// Update.
foreach ($oldOrders as $rawOrder) {
/* @var \App\Order $order */
$order = \App\Order::find(intval($rawOrder['id']));
// Check whether order is payed.
if ($order->isPayed() === FALSE && floatval($rawOrder["payedAmount"]) != 0) {
/* @var \App\Payment $payment */
$payment = new \App\Payment();
$payment->order_id = $order->id;
$payment->amount = $rawOrder["payedAmount"];
$payment->method = $rawOrder["paymentMethod"];
$payment->save();
}
}
}
在我从 shell 迁移的本地环境中。起点是/。但是对于这条路线,起点似乎是别的东西, File::get
抛出了一个异常。但是(无论如何)它从来没有被记录下来。我在迁移周围添加了 try{}catch(\Exception $e){}
并看到了错误。
我的应用程序中有一个迁移路径,当前输出是:
init migrate:install...done migrate:install
init with tables migrations...
现在它停止了。但是输出应该会继续。路线如下:
Route::get('/migrate', function () {
try {
try {
echo '<br>init migrate:install...';
Artisan::call('migrate:install');
echo 'done migrate:install';
} catch (Exception $e) {
echo 'allready installed';
}
echo '<br>init with tables migrations...';
Artisan::call('migrate', array('--force' => true)); // here it stops via browser
echo 'done with migrations';
echo '<br>clear view cache...';
$cachedViewsDirectory = app('path.storage').'/framework/views/';
if ($handle = opendir($cachedViewsDirectory)) {
while (false !== ($entry = readdir($handle))) {
if(strstr($entry, '.')) continue;
@unlink($cachedViewsDirectory . $entry);
}
closedir($handle);
}
echo 'all view cache cleared';
return redirect()->route('backend::dashboard');
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
});
在访问 Shell 和 运行 迁移时它将起作用:
-bash-4.2$ /opt/plesk/php/5.6/bin/php artisan migrate
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> yes
Migrated: 2016_08_23_194102_import_old_data
Migrated: 2016_08_25_080129_import_old_adresses
Migrated: 2016_08_25_080801_import_oldname_to_accountholder
为什么它在路由中不起作用?
更新
Apache 日志显示 "GET /migrate HTTP/1.0" return 状态 200,因此其 HTTP 正常。
在浏览器开发工具中也没有错误。
更新 2
另外 laravel.log 是空的。调用迁移路由期间没有新条目。
post 错误,打开开发工具 > 网络选项卡,或 apache 错误日志
好的,我知道了 运行。
原始迁移(如果我白痴发布它可能会有用)
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Load data to be imported.
$oldOrders = json_decode(File::get('storage/olddata.json'), TRUE);
// Update.
foreach ($oldOrders as $rawOrder) {
/* @var \App\Order $order */
$order = \App\Order::find(intval($rawOrder['id']));
// Check whether order is payed.
if ($order->isPayed() === FALSE && floatval($rawOrder["payedAmount"]) != 0) {
/* @var \App\Payment $payment */
$payment = new \App\Payment();
$payment->order_id = $order->id;
$payment->amount = $rawOrder["payedAmount"];
$payment->method = $rawOrder["paymentMethod"];
$payment->save();
}
}
}
现在迁移
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Load data to be imported.
$oldOrders = json_decode(File::get(base_path('storage/olddata.json')), TRUE);
// Update.
foreach ($oldOrders as $rawOrder) {
/* @var \App\Order $order */
$order = \App\Order::find(intval($rawOrder['id']));
// Check whether order is payed.
if ($order->isPayed() === FALSE && floatval($rawOrder["payedAmount"]) != 0) {
/* @var \App\Payment $payment */
$payment = new \App\Payment();
$payment->order_id = $order->id;
$payment->amount = $rawOrder["payedAmount"];
$payment->method = $rawOrder["paymentMethod"];
$payment->save();
}
}
}
在我从 shell 迁移的本地环境中。起点是/。但是对于这条路线,起点似乎是别的东西, File::get
抛出了一个异常。但是(无论如何)它从来没有被记录下来。我在迁移周围添加了 try{}catch(\Exception $e){}
并看到了错误。