2013-08-26 37 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