All artisan commands throw PDOException - laravel

I have run into an extremely weird problem. At first I encountered it during migrations, but since then it is happening in all commands. Even composer install and php artisan serve tell me this:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.patent_examination_types' doesn'
t exist (SQL: select * from `patent_examination_types`)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.patent_examination_types' doesn'
t exist
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.patent_examination_types' doesn'
t exist
I've tried composer dump-autoload, which says Generating autoload files and then if I say php artisan serve I get the same result.
I'm quite puzzled!

It seems that your have deleted your 'patent_examination_types' table from the database but this table is using in your code.
Check your code for 'patent_examination_types' table, Maybe you have write this table in you some controller or model, Search this table throughout your code and comment it..
Hope it helps.

Related

Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table

I am facing this error on my website while viewing the product page.
its a e-commerce website
Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘quietqre_QuietQrewHerbal.product_queries’ doesn’t exist (SQL: select count(*) as aggregate from `product_queries` where `product_id` = 15 and `customer_id` != 9)
Table product_queries in your database quietqre_QuietQrewHerbal is not exist. you need migrate database.
If it's new, use php artisan migrate
and if it's old migration and deleted by mistake or etc... find related migration row in migrations table (showed in image) and delete just that row, and use php artisan migrate

I been suffering a problem when I run php artisan migrate command

When I run php artisan migrate command then I see this error. I have an idea for this error is that I deleted the product migration from the migrations table. What can I do to migrate the product table?
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'products' already exists (SQL: create table products(idbigint unsigned not null auto_increm ent primary key, category_id int not null, subcategory_id int not null, product_name ...) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at F:\xampp\htdocs\suzayetstore\vendor\laravel\framework\src\Illuminate\Datahase\Connection.php:742
F:\xampp\htdocs\suzayetstore\vendor\laravel\framework\src\Illuminate\Database\Connection.php:527 PDOException::("SQLSTATE[42501]: Base table or view already exists: 1050 Table 'products' already exists")
This issue happens because you already have a table in your database and you are trying to migrate the same table without droping(deleting) it. You have 2 options which I have explained below,
If you already dont have any datas in your database tables. Then you can use,
php artisan migrate:fresh
So that all the tables will be deleted and recreated again.
If you need already have datas in any of your table in your database. And you need the datas. You just need to delete the table from database. For that use the query below,
drop table tablename;
And then, run the below command,
php artisan migrate

Artisan skipping migrations

So, I've just pulled down a project in Laravel 5 from Github that I've done no work on before, but I need to set up to add a feature or three.
Problem is, I don't have any of the database tables for this project. That should be easy enough to fix, as the migrations are all there in the proper folder.
I run php artisan migrate and it tells me that there's a problem with one of the migrations trying to update a table that doesn't exist.
The problem is, that isn't the first migration by date. And an earlier migration should create the table it's saying isn't there yet.
Basically, it's something like this:
Migration 1
Migration 2
Migration 3
Migration 4
Migration 5 <--- here's where the error is occurring
Migration 6
etc....
It doesn't appear to be running migrations before the migration that throws an error at all, and it's not writing anything to the migrations table in that schema.
The error(s) I'm getting is:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'table1' doesn't exist (SQL: select * from `table1` where `code` = DEFAULT_ADDRESS limit 1)
and
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'table1' doesn't exist
Needless to say, I'm a bit confused as to why it would skip migrations, even ones that don't concern that table.
You should run:
php artisan migrate:status
It should show you migrations in the order they should be run. Make sure the order is valid. If it's not probably something was messed up it you might need to alter files to have valid order of your migrations.

Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.people' doesn't exist

i made a migration named persons while i want to import data useing tinker then error showing i made a migration named persons while i want to import data useing tinker then error showing Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.people' doesn't exist (SQL: selec
This error can be caused when your database table has not created correctly.
You must to create your models and migration files first.
To create them you can run this command (for example):
php artisan make:model People -m
Then, after all configurations in the People model class and in the migration file - run:
php artisan migrate
This will create all the migration tables in the database.
p.s. don't forget to check your .env file for the correct database name.
...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<your_database_name>
DB_USERNAME=<your_username>
DB_PASSWORD=<your_password>
...
One should be sure what model name are they using to create a model and what the error is coming. LARAVEL naming convention adds-up 's' assuming the table name ends with 's', e.g, in case you create a model with the name of 'dummy_project' as well as you have table 'dummy_project' it will add 's' to the end and if you run App\dummy_project in the tinker, it will produce the error:
*Illuminate/Database/QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tutorial.dummy_projects' doesn't exist (SQL: select * from dummy_projects)'*
All we need to do is to add the following line of code into the model:
protected $table = 'table_name'; === explaination ===
In case your table name is 'dummy_project' and you created a model name is 'dummy_project' too, the code in the model should be like following:
*
**<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class dummy_project extends Model
{
**protected $table = 'dummy_project';**
}**
*
Please bear in mind, the model_name can be different than the table name, but 'protected $table = 'table_name' ' should always refer to the relevant table name in the DATABASE!
You must create the table by hand in the database so I will solve it because if you verify your database the table does not exist, so the warning.

php artisan migrate gives error [PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
drop the database then create the database again before migrating.

Resources