Error on php artisan migrate - php

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.

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.

Laravel Error - Base table or view not found

I am trying to run this code I cloned, but I keep getting this error..
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'roocket.permissions' doesn't exist (SQL: select * from `permissions`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'roocket.permissions' doesn't exist-Vue-Dashboard/blob/master/src/pages/Pages/RTLPage.vue
I have run composer install and npm install , and I am new to the laravel world.
I have uploaded the repo to my github https://github.com/arya107/laravelbackend.
I have connected the DB via XAMPP and I don't know what the problem is.
Basically, the fix for me was that I needed to comment out
{
Gate::define($permission->name , function ($user) use($permission){
return $user->hasRole($permission->roles);
});
}
Then, I was enabled to install it, and then I re-enabled the code :)
php artisan migrate
You are missing the DB table. Run the migrations included in the project to create the tables in your DB.
The migration is creating the field and relationship at same time. I would try to use separated migrations, as this answer explains:
But I always create a foreign key in a separate Schema::table() command, because some databases need you to have the column before attaching the constraint to it
I think (haven't tried it) that your database engine does not accept the creation of the foreign key relation because the FK field was not created yet.
You can also try to do a full migrate using:
php artisan migrate:fresh
That command will drop all your database tables, so be careful!

Something wrong with my Laravel

there's defenitely something wrong with my Laravel.
I have the Laravel 5.4 installed. I have installed Composer on my windows globally. I have php artisan working, but I'm getting errors everywhere:
php artisan tinker
When I type in php artisan make:model Brand it says Model created succesfully.
Awesome, right? When I type in php artisan tinker and App/Brand::all() next, it says Class 'Brand' not found.
While I have Brand.php inside my app folder:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
//
}
By the way, I'm following this series at laracast.
mySQL
I can't run the mysql command, though I have manually installed mySQL on my windows (globally as well).
It says
'mysql' is not recognized as an internal or external command,
operable program or batch file.
migrate
php artisan migrate gives me this error:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes
Besides this php artisan migrate is working very well, it creates two tables for me: migrations and users. I thought that was because I have two files in my \database\migrations folder. But...
When I say php artisan make:migration create_brands_table --create=brands, it creates a file inside this folder indeed. Like it should. I add a few lines inside the up() function so it looks like this:
Schema::table('brands', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('description');
$table->timestamps();
});
But it does not create a table.
Please note that I did edit my .env file to make a proper database connection, otherwise php artisan migrate would not work on the other two tables I did create with the php artsian migrate command.
It only gives a alreadt exists error. I tried migrate:rollback and migrate:refresh as well. I tried doing this after the composer dump-autoload command, but it came with the same result.
I'm lost in the dark here, I am obviously new to Laravel, but some friends of mine who are familiar with Laravel have never experienced the problems I have.
I have tried to reinstall and create a new project and all... guess what: same results.
You got namespaces wrong, use backslash: App\Brand
To create a table use Schema::create and not Schema::table
The mysql part is not Laravel's concern and should not be in this question. Anyway you should check your environment PATH variable.
Regarding the already existing table issue, I ran into that before and here's what I've done, first delete your database file, in my case I was using sqlite so my file was database.sqlite, I deleted that and created a new one(don't delete it permanently just in case), run your migrations normally to be sure everything is working for the normal tables, also delete your old Brand migration, then when you are creating a new migration for your Brands table, lose the --create flag,
Just like this php artisan make:migration create_brands_table, at this point do as mentioned before and use the Schema::create instead of Schema::table, hopefully everything should be working fine now.

php artisan - unknown table error on any command

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.

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