Class CreateTableName Not found php artisan - php

when i typed in console - php artisan make:migration create_website_table --create=website
than file created, I didn't edit anything and ran command php artisan migrate
now i want to rollback it and it says
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'CreateWebsiteTable' not found
The code of my migration Website class
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateWebsiteTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('website', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('website');
}
}
Maybe there is some namespaces?

Before you run php artisan migrate, run the following code
composer dump-autoload.
Infact, whenever you get ClassNotFound Exception, run the above command!

Related

Laravel - When using make:migration created tables in database generates empty migration file

I`m running a new installation of Laravel, with clean database and files.
I created a table named "frooth" and it has the columns id, title and created_at (id PK, varchar and datetime)
When I run "php artisan make:migration frooth" command, the created migration file is empty, only containing the up() and down() functions and nothing more (no columns)
How can I solve this, I followed the basic configuration of the framework as documented in official website, I can access and create functions in artisan as expected, only migrations its not working.
I generated the project with the command: composer create-project --prefer-dist laravel/laravel blog
create table laravel.frooth
(
id int auto_increment
primary key,
title varchar(250) null,
created_at datetime null
);
The PHP class generated in database/migrations/2019_10_25_012925_frooth.php:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Frooth extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
//
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
//
}
}
Console output:
php artisan make:migration frooth
Created Migration: 2019_10_25_012925_frooth
Delete that table you made manually and delete that migration file.
Run php artisan make:migration create_frooths_table
Then add your columns to the new migration file.
Something similar to this:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Frooth extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('frooths', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('frooths');
}
}
Then run php artisan migrate
For the id you might need to use $table->bigIncrements('id'); if using Laravel 6

Want to add column but migration class is not found even It exists

I am learning Laravel.
Here is my migration file code.
class CreatePostTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('post', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned(); // i want to add this column after adding this line i runs the command refresh but it shows below errors.
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('post');
}
}
Now I have a problem that whenever I run this command in terminal in PhpStorm:
php artisan migrate:refresh
it shows following errors:
PHP Fatal error: Class 'AddIsAdminColumnToPostTable' not found in C:\xampp\htdocs\cms\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php on line 335
Symfony\Component\Debug\Exception\FatalErrorException]
Class 'AddIsAdminColumnToPostTable' not found
I tried composer dump-autoload in terminal solution from here but it's not working. I also used rollback command but still having issue.
How can make refresh this?
Artisan looks for migrations based on the file name. If you want it to be called something else: rollback, delete the migration, make a new migration. Or, change the file name to exactly match the class name.
For you, try changing
class CreatePostTable extends Migration
to
class AddIsAdminColumnToPostTable extends Migration

Laravel 5.2 base table or view not found error

i have just started working with laravel 5.2.. this is a simple migration file but when i run the php artisan migrate command i get the error shown on the screenshot. what should i do now?
migration file
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductCategoryTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('product_category', function (Blueprint $table) {
$table->increments('id');
$table->string('product_category_name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('product_category');
}
}
You need to change Schema::table to Schema::create.
For me, it was because i was dynamically registering Scheduled Tasks in Kernel.php via my own custom Task object by loop over Task::all(). But my 'task' db table wasn't created yet causing the error. so I commented out the Kernel.php code, ran the php artisan migrate command then uncommented my Kernel.php code.
Not sure, but may be best to just do a try{ dbCode; } catch{doNothing;} in the Kernel.php code.

Laravel class not found after migrating the file

I am using Laravel Stapler for image purposes and after migrating the new table, I attempt to artisan migrate:refresh afterwards and I am shown this error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'AddPhotoFieldsToStaffTable' not found
However, I can see the file within my migration's folder and using php artisan migrate, before trying to --refresh it, it successfully migrated!
The file that was generated is:
class AddPhotoFieldsToStaffTable extends Migration {
/**
* Make changes to the table.
*
* #return void
*/
public function up()
{
Schema::table('staff', function(Blueprint $table) {
$table->string('photo_file_name')->nullable();
$table->integer('photo_file_size')->nullable()->after('photo_file_name');
$table->string('photo_content_type')->nullable()->after('photo_file_size');
$table->timestamp('photo_updated_at')->nullable()->after('photo_content_type');
});
}
/**
* Revert the changes to the table.
*
* #return void
*/
public function down()
{
Schema::table('staff', function(Blueprint $table) {
$table->dropColumn('photo_file_name');
$table->dropColumn('photo_file_size');
$table->dropColumn('photo_content_type');
$table->dropColumn('photo_updated_at');
});
}
}
Any help would be greatly appreciated.
Using composer dumpautoload solved this issue.
Just do the command
composer dump-autoload

Why does php artisan migrate nothing?

Running "php artisan migrate" does nothing: no database modifications, no message(olso no "nothing to migrate"), no error.
No records are being added to table migrations as well.
Previously, the command "php artisan migrate" was working fine.
One of the migration files in folder database/migrations has this content:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class VidsTableEdit14 extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('vids', function(Blueprint $table)
{
//
$table->integer('test');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('vids', function(Blueprint $table)
{
//
});
}
}
How to make "php artisan migrate" working?
If the migration stops working suddenly there is probably a syntax error somewhere in one of your migrations. If you suddenly get a class not found error be suspicious of a syntax error.
This same happened me, when I was trying to add soft delete to my table.
I created the migration and in the Schema::table function I typed "$table->softDelete();". Instead of
$table->softDeletes();
Notice the 's' for plural, I tried running migration and didn't get any error or message. I made it plural and it worked.
And I noticed that you didn't make down function().Try adding:
Schema::drop('vids');
And run the migration again.
Error:
SQLSTATE[42S01]
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
-------------
[php artisan migrate]
Solution: Go to:
app\Http\Providers\AppServiceProvider
import ( use Illuminate\Support\Facades\Schema; )
And, inside the register() function, insert this code:
public function register()
{
Schema::defaultStringLength(191);
}
Then run:
php artisan migrate:fresh

Categories