Laravel : [PDOException] SQLSTATE[42S02]: Base table or view not found - php

I'm trying to build a laravel application where I have already create all the migration file. But when I tried to run the
php artisan migrate
command, I saw the following Error :
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'atom.users' does
n't exist (SQL: select exists(select * from `users`) as `exists`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'atom.users' does
n't exist
I tried to update the composer and migrate:rollback But same Error I'm getting whenever I run the commands.Besides that there is no error with the .env files as well.I couldn't find what's the Error, if any one could help me to find the problem ..Thank you.
Here is my user table migration file :
<?php
use Illuminate\Support\Facades\Schema;
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');
}
}

here's my history on the migration of user.
php artisan make:auth
php artisan make:model User
php artisan make:model User --migration
php artisan migrate:install
sudo php artisan migrate:install
sudo php artisan make:migration
sudo php artisan make:migration users
Btw, your migration file seems ok, hope this will help you
If it doesnt, try to "fake" some data in db table, and try again...

Run: php artisan clear-compiled then run your migration again.

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