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
Related
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
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.
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!
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
I created a migration script that creates a table called Archives.
It has 4 columns not including timestamps/increments.
The tables columns are name, title, content and image.
I need to drop the image column as it is no longer needed.
I have not been able to find a way to do this by searching and was hoping someone could give me the best way to do this.
I attempted to accomplish this by creating a new migration and then running
php artisan migrate:rollback --pretend
But this tries to roll back the previous migration.
class DropImageColumnArchive extends Migration
{
/**
* Run the migrations.
* #return void
*/
public function up()
{
Schema::table('archives', function ($table) {
$table->text('image');
});
}
/**
* Reverse the migrations.
* #return void
*/
public function down()
{
Schema::table('archives', function ($table) {
$table->drop_column('image');
});
}
}
Almost there change drop_column to dropColumn
Referenced Here http://laravel.com/docs/schema#renaming-columns
Schema::table('users', function($table)
{
$table->dropColumn('votes');
});
Edit Referenced here for 5.1 http://laravel.com/docs/5.1/migrations