Why does php artisan migrate nothing? - php

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

Related

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

Class CreateTableName Not found php artisan

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!

Importing Mysql statements into Laravel

I'm new to using Laravel.
I have a .sql file where created a whole bunch of tables("CREATE TABLE my_table......."). Is there a way to somehow import these statements into Laravel? I could always manually rewrite these tables in raw php, but I feel that this would take too long and there is possibly an easier way to do it.
You would use migrations in Laravel to do this for example
I want to create a table called tasks I would use this command in artisan
php artisan make:model Task
This would create a model called task and a migration for this table.
You can then access the migration file and input something like this
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTasksTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('tasks', function (Blueprint $table) {
$table->increments('task_id');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('tasks');
}
}
You would then run the artisan command to create this table
php artisan migrate
This then automatically creates your table.
Its a very useful feature and you can also rollback your migrations or even refesh it meaning it will remove the table and then reinstate it with no data in.
php artisan migrate:refresh
link to the docs
http://laravel.com/docs/5.1/migrations

Categories