Fix auto increment bug

This commit is contained in:
An Phan 2016-07-09 13:57:59 +08:00
parent 77fa77081d
commit b8d68bd74f
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2

View file

@ -0,0 +1,36 @@
<?php
use App\Models\Artist;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class FixArtistAutoindexValue extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This is to fix the auto increment bug caused by 2016_04_16_082627_create_various_artists
// Return if the database driver is not MySQL.
if (DB::getDriverName() !== 'mysql') {
return;
}
$latestArtist = Artist::orderBy('id', 'DESC')->first();
DB::statement("ALTER TABLE artists AUTO_INCREMENT=".($latestArtist->id + 1));
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}