Laravel artisan migrate command not running on Homestead - php

I recently just setup laravel homestead on my development machine and everything has been smooth and I love it. However, I am trying to add some columns to an existing table using migration but when running the php artisan migrate command doesn't complete. It seems to start but never completes even after leaving it for more than 10mins.
Here's my migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddColumnsToTransfersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('transfers', function (Blueprint $table) {
$table->integer('otp')->after('bank_code')->nullable();
$table->boolean('authorized')->after('otp')->nullable()->default('0');
$table->string('recipient_code')->after('authorized')->nullable();
$table->boolean('approval_required')->after('recipient_code')->nullable()->default('0');
$table->unsignedBigInteger('approved_by')->after('approval_required')->nullable();
$table->foreign('approved_by')->references('id')->on('users')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('transfers', function (Blueprint $table) {
//
});
}
}
And this is the result of the command php artisan migrate
I know db connection is fine as I am able to login and pull data from the database inside the application. I was able to generate the migration file using php artisan make:migration command so I have no idea why is seems to be stuck when I try to run the actual migration.

It seems there was an issue with mysql service. So I stopped the service by running sudo service mysql restart then ran php artisan migrate, and the table was successfully migrated. Problem solved.

Related

Laravel migrate:refresh Doesn't Work After Composer Update

The command in the title return error message below:
Type error: Too few arguments to function
Illuminate\Database\Schema\Builder::create(), 1 passed in
C:\xampp7\htdocs\assurance-web\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php
on line 221 and exactly 2 expected
I installed the framework with the commands:
composer create-project --prefer-dist laravel/laravel assurance-web
version 5.7
Then executed:
php artisan make:migration create_banks_table --create=banks
I was able to run php artisan migrate with no errors. However, then when I run php artisan migrate:refresh I get the error above.
This is "2018_12_04_033726_create_table_banks.php":
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBanksTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('banks', function(Blueprint $table) {
$table->increments('id');
$table->string('bank_name');
$table->string('bank_code');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('banks');
}
}
Maybe your migration table is compromised.
You can use:
php artisan migrate:fresh
instead of "php artisan migrate:refresh" and the migration will see that it will work.
The "php artisan migrate:fresh" command physically deletes all tables instead of rolling back.

Laravel 5.3 db:seed command simply doesn't work

I do everything by-the-book:
Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error)
run php artisan make:auth
create migrations for a new table
`php artisan make:migration create_quotations_table --create=quotations
Schema::create('quotations', function (Blueprint $table) {
$table->increments('id');
$table->string('text');
// my problem persists even with the below two columns commented out
$table->integer('creator_id')->unsigned()->index('creator_id');
$table->integer('updater_id')->unsigned()->index('updater_id');
$table->softDeletes();
$table->timestamps();
});
Then I run php artisan migrate
Then I define a new seed php artisan make:seeder QuotationsTableSeeder
The complete content of the file, after I add a simple insert:
<?php
use Illuminate\Database\Seeder;
class QuotationsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
DB::table('quotations')->insert([
'text' => str_random(10),
]);
}
}
Then I run php artisan db:seed
problem
it simply doesn't work. No feedback presented, no errors in log file.
The probem persists in both my local environment (Win7, newest WAMP server)
and my Digital Ocean VPS powered by Ubuntu 16.04.
All the above steps I took in several separate apps - for no result. Also under Laragon 2.0.5 server.
what I have tried
php artisan optimize as suggested here.
composer dump-autoload i php artisan clear-compiled also have brought no results
I also tried to seed just following the official docs example - failed.
I added use DB; to the seed file - still no result.
to do
help!!! How come they don't work?
Are you calling your seeder inside the DatabaseSeeder class? This way:
database/seeds/DatabaseSeeder.php
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
$this->call(QuotationTableSeeder::class);
}
}
Or, add the --class option when using the php artisan db:seed command, this way:
php artisan db:seed --class="QuotationTableSeeder"
After creating or removing your seeders, don't forget to run the following command:
composer dump-autoload
NB:
Please use with caution on DEV ENVIRONMENT and/or DISPOSABLE DATABASES ONLY
If anybody else is having issues with migrating AND seeding at the same time, please try
php artisan migrate:fresh --seed
Worked for me..

Laravel migration not working

I tried to implement the default auth login system in laravel
php artisan make:migration create_users_table
Created Migration: 2016_03_10_115611_create_users_table
On running the above command only migration file is created and not the tables are created.
Also i have tried to reinstall composer but it didn't work
//In 2016_03_10_115611_create_users_table file
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
on running
php artisan migrate
it took a few amounts of time and returned
[ErrorException]PDO::__construct(): MySQL server has gone away
Thanks to everyone i have not configured the .env file properly so that it doesn't work
What's your MySQL version?
Or you not yet modify .env
Try SQLite and change settings database to sqlite. I think this problem on php extension.
First you have run this command to install migration
php artisan migrate:install
Note :- if you look at database/migrations there will be already two migrations files
2014_10_12_000000_create_users_table.php
2014_10_12_100000_create_password_resets_table.php
php artisan migrate

How can I tell if Elastic Beanstalk is running my config files?

I'm getting an error on my deployed application:
Base table or view not found: 1146 Table 'ebdb.users' doesn't exist
This leads me to believe my php artisan migrate command isn't working, and the users table isn't being created.
This is one of my config files (in my .elasticbeanstalk folder)
container_commands:
00testCommand:
command: "echo test"
01migrateSeed:
command: "php artisan migrate --force"
02seed:
command: "php artisan db:seed --force"
This is my create users migration file:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('referral_id')->unique();
$table->string('referred_by')->nullable()->default(null);
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
Am I missing something obvious? Is this error not related to my migration? I'd like to know if these commands are even being run, but can't find them in the Elastic Beanstalk environment log.
Any help appreciated, thanks.
move the config file to the .ebextensions folder. it does not belong to the .elasticbeanstalk one

Can't rollback laravel migrate

I've created a migration for CreateUserTable successfully.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('user', function(Blueprint $table)
{
$table->increments('id');
$table->string('email')->unique;
$table->string('password', 60);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('user');
}
}
but I'm not able to rollback:
$ php artisan migrate:rollback
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'CreateUserTable' not found","file":"C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Migrations\\Migrator.php","line":301}}
Someone suggested to run below but it give me an other error:
$ composer dump-autoload
Composer could not find the config file: C:\ProgramData\ComposerSetup\bin
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
Any solution to rollback and avoid this second error related to composer.json? I'[m using Laravel 4 with fresh installation.
Rollback often requires you to run composer dumpautoload first. I've had the same problems in Laravel 5.1.
In your case dumpautoload should be in one word - this way it works for me.
And of course composer should be run in a folder that contains the composer.json file. This would be your Laravel project folder.

Categories