Can't rollback laravel migrate - php

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.

Related

Laravel artisan migrate command not running on Homestead

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.

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 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

Laravel Artisan Migrate Not Creating Tables

I have followed the tutorial (here) to setup my app. Then I tried to replicate the steps to create more tables, so I ran a few command in the terminal like:
php artisan migrate:make create_generalUserInfo_table
Then in the create_generalUserInfo_table file I added:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateGeneralUserInfoTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('generalUserInfo', function($table){
$table->increments('id');
$table->integer('user_id');
$table->string('firstname', 100);
$table->string('lastname', 100);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('generalUserInfo');
}
}
Then Back to terminal I ran:
php artisan migrate:refresh
It is adding the migrants but the tables are not being create in mysql. the Users table from the initial tutorial was created
Migrated: 2015_01_28_055418_create_users_table
Migrated: 2015_01_28_213951_create_imprints_table
Migrated: 2015_01_28_214023_create_generalUserInfo_table
Migrated: 2015_01_28_214103_create_roles_table
Migrated: 2015_01_28_214114_create_role_user_table
Migrated: 2015_01_28_214146_create_comments_table
Migrated: 2015_01_28_214159_create_books_table
Try to change this line:
Schema::create('generalUserInfo', function($table){
to
Schema::create('generalUserInfo', function(Blueprint $table){
and run the migration command like this:
php artisan migrate
You should also make sure that
your migration table doesn't have those tables inserted as migrated
your database credentials are correct and point to the correct DB

Categories