php artisan - unknown table error on any command - php

For some reason whenever I run any php artisan command I get an error saying one of my tables doesn't exist. This is true, I'm starting on a new database. What I can't figure out is why on earth artisan needs to use this table? The error that shows up is:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'happylister.categories' doesn't exist (SQL: select *
from `categories` order by `name` asc)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'happylister.categories' doesn't exist
I just can't figure out for the life of me where that query is coming from - even just using php artisan generates this error. I first noticed this when I tried to run php artisan migrate to set up the tables, which of course failed. Then I noticed ALL php artisan commands fail.
So my question is: why would php artisan need a table specific to my app, given that normally you should be able to use php artisan on a clean database to set it up?

A Laracasts user very kindly helped me out with this answer:
If you're referencing a model from a service provider and the
migrations have not been run, then you'll get that error. For some
reason Artisan commands like to load all the providers, even ones it
doesn't need.
Thank you to FetchTheDev over at the Laracasts forums.

Related

when i run the code "php artisan migrate --seed" that's not work completely

when i run this code "php artisan migrate --seed" qppeaer one error like
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'naryn.modules' doesn't exist (SQL: select * from modules where module = admin/backup_v2 limit 1)
Without seeing your database, stacktrace, and code this will be hard to answer.
But is this the first time that you ran the migration? If not, it's possible that you dropped the tables (the modules table specifically), but you did not drop the migration table. If the modules migration record still exists it will not run the migration and will not cause an error, hence going to the seeder even when there's no table migrated.
I would suggest if your still on the development phase and you can still drop the tables, just drop the schema and create it again to make sure it's a clean migration.

When creating the Laravel database tables, which of the terminal should I run first - Laravel 6?

I want to create the database from the terminal. And in this section, when I say php artisan migrate and then php artisan db: seed, my tables are created. When I do the opposite, that is, when I first say php artisan db: seed, I get the table not found error.
PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146
Table 'fibonacci.roles' doesn't exist")
C:\xampp\htdocs\Fibonacci\vendor\laravel\framework\src\Illuminate\Database\Connection.php:463
2 PDOStatement::execute()
C:\xampp\htdocs\Fibonacci\vendor\laravel\framework\src\Illuminate\Database\Connection.php:463
Please use the argument -v to see more details.
So is this the order for this error normal? Thank you.
Basically, what is php artisan migrate do is generate tables based on your migrations files and php artisan db: seed is to populate data inside specific table. Therefore, you need to have a table first then only data can be insert inside your table.
So to answer your question, yes the order for this error is normal.

Created a fresh database, now running any artisan command throws an error about a missing table

I wanted a fresh development database so I could seed with new data, so I manually dropped and recreated my development database and now running any artisan commands throws an error. I continuously get an error saying that I'm missing a table.
In Connection.php line 647:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'
doesn't exist (SQL: select * from `stores`)
In PDOConnection.php line 63:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'
doesn't exist
In PDOConnection.php line 61:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'
doesn't exist
I haven't run php artisan migrate:refresh in a long time so I'm not sure where the table stores is being used that's causing this error. Adding a -v flag doesn't provide any additional output to further trace the stack.
I've tried manually dropping the database and recreating it via the mysql. I've tried composer dump-autoload but that doesn't help either. I can't run php artisan migrate:install because calling ANY artisan command will throw the same error. Even calling php artisan throws the error. I've tried looking at my service providers to see if the table is being referenced in any of the constructors but I don't see it being used.
Is there anywhere in the code I should be checking for the use of this table? I'm not sure what is instantiated when php artisan is called.
The stores table is actually my first migration, so it's supposed to be the first thing created, but for some reason it's being called as a part of the artisan process.
As mentioned by #aynber in the comment to my question, the problem was several of my commands in the app/Console/Commands/* directory were instantiating an object in its constructor that referenced the Store model in its parent constructor. Specifically, it was running the line
$this->storeId = Store::get()->last()->id;
Commenting out this line allowed me to run my artisan commands.

Error on php artisan migrate

I have read many post on this subject, but have not found the right answer. When i write any command php artisan migrate returns a result:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'adtmart1.shop_categories' doesn't exist (SQL: select * f
rom `shop_categories`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'adtmart1.shop_categories' doesn't exist
I would like to move the finished website made using Laravel on the local web server. I use Web server - opensever. There php version - 5.5, Mysql - 5.5. All commands i write of the console opensever. While replying, please, take into consideration that I am new in this field
You use Schema::table to alter an existing table, you are looking for Schema::create which is used to create a new table.
Alter your migrations to use Schema::create and you'll have no trouble running your migrations:
Schema::create('name_of_table', function(Blueprint $table) {
{
$table->increments("id",true);
$table->string("username")->nullable()->default(null);
$table->string("password")->nullable()->default(null);
$table->string("email")->nullable()->default(null);
$table->timestamps();
});
I have of course used dummy columns and you would use your own.
More info on the problem here.
First of all, you'll need to post migration code that causes the error. To do this, try to run migrations one-by-one. Remove all migrations from /database/migrations folder and then add first one (first by date it was created) back into /database/migrations. Then run php artisan migrate. If migrations was successful, do all steps for secons migration etc. When you see an error, you'll know that this one migrations causes it. Post it here please, so we could help.

Doing a Laravel tutorial, getting "Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist"

Working through this tutorial, I'm down to the following step:
You should now be able to call migrate as many times as you want and it’ll work:
php artisan migrate:refresh
Upon running that command, I get the following errors:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist (SQL: select max(batch) as aggregate
from migrations)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist
Googling about the error (obviously without the site-specific table name) doesn't find any answers that seem to help.
Full disclosure: I'm new to Laravel, and to Stack Overflow for that matter, please go easy on me. :)
php artisan migrate will create the migrations table for you if it does not exist yet, then run any and all migrations that have not been run yet.
php artisan migrate:refresh is for resetting all existing migrations, then running them again. It expects the migrations table to already exist.
You can use php artisan list to list all available Artisan commands and their descriptions to learn more about these and other migration-related commands.

Categories