Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artisan::call('migrate') not working after upgrading Laravel to 4.2 #4721

Closed
ghost opened this issue Jun 15, 2014 · 9 comments
Closed

Artisan::call('migrate') not working after upgrading Laravel to 4.2 #4721

ghost opened this issue Jun 15, 2014 · 9 comments

Comments

@ghost
Copy link

ghost commented Jun 15, 2014

Wen I call this controller method:

public function ArtMigr(){
try {
Artisan::call('migrate');
} catch (Exception $e) {
echo $e;
}

}

I'm getting this error:

exception 'ErrorException' with message 'Use of undefined constant STDIN - assumed 'STDIN'' in D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php:112 Stack trace: #0 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php(112): Illuminate\Exception\Handler->handleError(8, 'Use of undefine...', 'D:\htdocs\artis...', 112, Array) #1 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php(49): Symfony\Component\Console\Helper\QuestionHelper->doAsk(Object(Symfony\Component\Console\Output\NullOutput), Object(Symfony\Component\Console\Question\ConfirmationQuestion)) #2 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(186): Symfony\Component\Console\Helper\QuestionHelper->ask(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput), Object(Symfony\Component\Console\Question\ConfirmationQuestion)) #3 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\ConfirmableTrait.php(21): Illuminate\Console\Command->confirm('Do you really w...') #4 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(59): Illuminate\Database\Console\Migrations\MigrateCommand->confirmToProceed()

5 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(112):
Illuminate\Database\Console\Migrations\MigrateCommand->fire() #6 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #7 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #8 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Application.php(96): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #9 [internal function]: Illuminate\Console\Application->call('migrate') #10 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Artisan.php(57): call_user_func_array(Array, Array) #11 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Foundation\Artisan->__call('call', Array) #12 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Foundation\Artisan->call('migrate') #13 D:\htdocs\artisan_error\app\controllers\HomeController.php(160): Illuminate\Support\Facades\Facade::__callStatic('call', Array) #14 D:\htdocs\artisan_error\app\controllers\HomeController.php(160): Illuminate\Support\Facades\Artisan::call('migrate') #15 D:\htdocs\artisan_error\app\controllers\HomeController.php(145): HomeController->InstallDatabaseStructure() #16 D:\htdocs\artisan_error\app\controllers\HomeController.php(127): HomeController->WriteDatabaseCredentials('localhost', 'laravel-aplikac...', 'root', '') #17 [internal function]: HomeController->postTestDatabaseConnection() #18 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(231): call_user_func_array(Array, Array) #19 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('postTestDatabas...', Array)

20 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(62):
Illuminate\Routing\ControllerDispatcher->call(Object(HomeController), Object(Illuminate\Routing\Route), 'postTestDatabas...') #21 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(930): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'HomeController', 'postTestDatabas...') #22 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}() #23 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Route.php(105): call_user_func_array(Object(Closure), Array) #24 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(996): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) #25 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(964): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

26 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(738):
Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

27 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(708):
Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))

28 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72):
Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true) #29 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true) #30 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true) #31 D:\htdocs\artisan_error\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true) #32 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request)) #33 D:\htdocs\artisan_error\public\index.php(49): Illuminate\Foundation\Application->run() #34 {main}

@ghost
Copy link
Author

ghost commented Jun 15, 2014

Migration files are:

increments('id'); $table->string('username'); $table->string('email'); $table->string('password'); $table->integer('admin')->default(0); $table->integer('active')->default(1); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('users'); } ``` } and increments('id'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('settings'); } ``` }

@letrunghieu
Copy link
Contributor

STDIN and STDOUT are available automatically when you run your app in command line. It seems that you call Artisan::call from an HTTP apache process and these variables will not be predefined.

To solve this problem, add this line into you controller, before calling Artisan::call

define('STDIN',fopen("php://stdin","r"));

@ghost
Copy link
Author

ghost commented Jun 16, 2014

It might be good idea that Laravel 4.2 checks it automatically

@zaalbarxx
Copy link

I can confirm that this is not working correctly in Laravel 4.2. I've had no issues at all in earlier versions, but 4.2 seems to struggle in that case.

@crynobone
Copy link
Member

It most likely a change from symfony/console. However I would highly recommend to avoid using Artisan::call() directly from a web interface. It not hard to create something like https://github.com/orchestral/publisher/blob/master/src/Publisher/MigrateManager.php to make this doable.

@alexgalletti
Copy link

If you must migrate from a web interface you can do Artisan::call('migrate', array('--force' => true));. Note that this will obviously ignore the migration confirmation due to the --force flag.

@GrahamCampbell
Copy link
Member

@collb - See the comments by @letrunghieu, @crynobone and @alexgalletti.

If you still have any questions, please ask on the forums/irc.

@bart
Copy link
Contributor

bart commented Oct 25, 2014

@crynobone Getting RuntimeException Aborted in vendor/symfony/console/Symfony/Component/Console/Helper/QuestionHelper.php line 146 now when defining STDIN.

@crynobone
Copy link
Member

@bart so? Been telling you not to use the hack. STDIN are defined for console request.

@laravel laravel locked and limited conversation to collaborators Oct 25, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants