2013-08-26 40 views
0

這是我的問題。如何在laravel4中運行未完成的遷移?

我有這樣的路徑內的遷移2013_08_25_220444_create_modules_table.php:

應用程序/模塊/用戶/遷移/

我已創建的自定義命令工匠:

<?php 

use Illuminate\Console\Command; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Input\InputArgument; 

class UsersModuleCommand extends Command { 

/** 
* The console command name. 
* 
* @var string 
*/ 
protected $name = 'users:install'; 

/** 
* The console command description. 
* 
* @var string 
*/ 
protected $description = 'Instala el modulo de usuarios.'; 

/** 
* Create a new command instance. 
* 
* @return void 
*/ 
public function __construct() 
{ 
    parent::__construct(); 
} 

/** 
* Execute the console command. 
* 
* @return void 
*/ 
public function fire() 
{ 
    echo 'Instalando migraciones de usuario...'.PHP_EOL; 
    $this->call('migrate', array('--path' => app_path() . '/modules/user/migrations')); 




    echo 'Done.'.PHP_EOL; 
} 

/** 
* Get the console command arguments. 
* 
* @return array 
*/ 
protected function getArguments() 
{ 
    return array(
     //array('example', InputArgument::REQUIRED, 'An example argument.'), 
    ); 
} 

/** 
* Get the console command options. 
* 
* @return array 
*/ 
protected function getOptions() 
{ 
    return array(
     //array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), 
    ); 
} 

} 

在火災( )方法,我調用migrate命令並傳遞一組選項。

然後,在我的終端,運行此命令:

PHP工匠用戶:安裝

,我是這樣的輸出:

Instalando migraciones德usuario ... 沒有遷移。 完成。

問題是遷移無法運行。

但是,如果我在終端運行此命令:

PHP人員遷移--path =應用​​程序/模塊/用戶/遷移

一切工程確定,它運行遷移2013_08_25_220444_create_modules_table.php

注意:我已經在app/start/artisan.php文件中註冊了artisan命令:

Artisan :: add(new UsersModuleCommand);

我在做什麼錯?

對不起我的英語:d

回答

1

注意如何在命令行上傳遞的路徑是相對於應用程序的根,但是你對你的命令傳遞的一個是絕對的?你應該在你的命令調用是:

$this->call('migrate', array('--path' => 'app/modules/user/migrations')); 

順便說一句,因爲你可能有一天要回滾這些遷移,您添加app/modules/user/migrationscomposer.json的classmaps有趣的是:

composer.json

... 
"autoload": { 
    "classmap": [ 
     ... 
     "app/modules/user/migrations", 
    ] 
}, 
+0

它可以完美運行:d,謝謝!!!!!!! – user2403824