Why is Laravel 6.x creating a failed_jobs migration by default - php

I am creating a messages table in Laravel migrations but it's creating another table too called create_failed_jobs_table. I didn't create this, its a new project. It's happening in every project that I create it automatically creates this table too while creating also the other table, I don't know if its something I've done that creates it. Here is this file:
create_failed_jobs_table):
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
create_messages_table:)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMessagesTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('messages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('messages');
}
}

To answer your question so that your question can be marked as answered: the failed_jobs table comes default with all Laravel 6.x projects. You can check the release note for other things that changed in release 6.0.
Notice that Laravel 6.0 also added a new driver option to the config. That's probably why they've also included the migration by default.

Related

Laravel 9 Migration classname is not being applied from stub

I am trying to create a model along with migration as follows:
php artisan make:model Candidate -m
The output is:
Model created successfully.
Created Migration: 2022_08_06_165641_create_candidates_table
Now on the migration file:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class {{ class }} extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('candidates', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('candidates');
}
}
Everything is fine except classname of migration file.
I tried deleting vendor folder, reinstalling composer packages and clearing config. But the problem still persists.

Include migration file in phpcs

I realize this goes against proper coding standards but I don't care.
I want my migration files checked by PHPCS.
I removed the following line from my phpcs.xml file.
<exclude-pattern>*/migrations/*</exclude-pattern>
I then formatted the following migration file to see if it was working.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class MigrationExampleClass extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('agreements', function (Blueprint $table) {
$table->unsignedInteger('subject_id')->nullable()->change();
$table->string('subject_type')->nullable()->change();
$table->dropUnique('agreements_type_user_id_subject_id_version_uniqueso;jfgjdfjgisdgjdfidfgjddfifgbjfgnidfbjdfbjfgnjdfbjdfvjdfbjdfbj');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('agreements', function (Blueprint $table) {
$table->string('subject_id')->change();
$table->string('subject_type')->change();
$table->unique(['type', 'user_id', 'subject_id', 'version']);
});
}
}
This would get flagged by PHPCS if this were a normal php file but it isn't.
Is there something else I have to do to get my migration files checked?

migrate not working after pivot migration of Laravel 5.3

migrate generates the exception after pivot migration of Laravel 5.3.
schema1 : software_houses
schema2 : skill_domains
I generated the command make:migration:pivot skill_domains software_houses
and the migration is created by the name of skill_domain_software_house
but when I execute php artisan migrate
following error occurs :
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'CreateSkillDomainSoftwareHousePivotTable' not found
See this Image
SKILL Domain
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSkillDomainsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('skill_domains', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('skill_domains');
}
}
Software House
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSoftwareHousesTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('software_houses', function (Blueprint $table) {
$table->increments('id');
$table->string('name',100)->unique();
$table->string('desc',500);
$table->string('url',100);
$table->string('rating')->default('3');
$table->string('logo')->nullable();
$table->string('city')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('software_houses');
}
}
Pivot table created after running the make:migration::pivot command
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSkill_domainSoftware_housePivotTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('skill_domain_software_house', function (Blueprint $table) {
$table->integer('skill_domain_id')->unsigned()->index();
$table->foreign('skill_domain_id')->references('id')->on('skill_domains')->onDelete('cascade');
$table->integer('software_house_id')->unsigned()->index();
$table->foreign('software_house_id')->references('id')->on('software_houses')->onDelete('cascade');
$table->primary(['skill_domain_id', 'software_house_id']);
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('skill_domain_software_house');
}
}
Try with below class name line:
class SkillDomainsSoftwareHouses extends Migration
Make sure the file name should be match with class name Documentation.
UPDATE
I think you should try this:
first remove above software_houses,skill_domains from migrations folder also remove from migrations table in your database then follow below steps :
1) php artisan make:migration skilldomain
2) php artisan make:migration softwarehouses
3) php artisan make:migration:pivot skilldomains softwarehouses
4) php artisan migrate

Laravel: Migrations do not work

I have created a file Order.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
/**
* The table associated with the model.
* #var string
*/
protected $table = 'order';
}
Then I have created a migration, called 2016_01_01_111111_create_orders_table.php:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOrdersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('order', function (Blueprint $table) {
$table->increments('id');
$table->string('orderIdent');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
//
}
}
Then I did the migration with
php artisan migrate
Then, I wanted to add some fields, created a new migration file called 2016_01_02_111111_alter_orders.php:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterOrders extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
//
Schema::table('order', function(Blueprint $table)
{
$table->string('selecteddate');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
//
}
}
Then again I did
php artisan migrate
But now I get this message in console:
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'order' already exists
What do I need to do, to add the new fields to my table?
Thanks in advance!
Adding this as an answer vs a comment to show what needs to be done. Since rollback was done, up needs to be commented out for now.
public function up()
{ /*
Schema::create('order', function (Blueprint $table) {
$table->increments('id');
$table->string('orderIdent');
$table->timestamps();
}); */
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('order');
}
Try this
public function up()
{
//
Schema::table('order', function($table)
{
$table->string('selecteddate');
});
}
remove Blueprint.
Try this :
php artisan migrate:refresh

How to check database table which has been created in laravel 4.2?

I'm new in laravel, anyone know how to see database table which has been created? I've been migrate the database and stuck after create table using schema builder. This is my code
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
//
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('nim');
$table->string('name');
$table->string('password');
$table->string('level');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
//
}
}
The new table name will be "users" because you have given 'users' as the name in the Schema::create function.
You can view the table from phpmyadmin if you are using the mysql database, which is sat as the default database for laravel.

Categories