Laravel 刷新时未在“迁移”中创建记录 table
Laravel does not create a record in `migrations` table on refresh
我有一个尴尬的问题,每两次我 运行 php artisan migrate:refresh --seed
migrations
table 是空的,虽然它应该在迁移后添加初始迁移记录: 2018_05_02_114819_add_initial_migration
这是我的迁移代码(它是旧数据库模式的导入):
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInitialMigration extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('users')){
DB::unprepared(File::get(database_path('sam.sql')));
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0');
foreach (DB::select('SHOW TABLES') as $table) {
$table_array = get_object_vars($table);
if($table_array[key($table_array)] !== 'migrations'){
DB::statement('DROP TABLE ' . $table_array[key($table_array)]);
}
}
DB::statement('SET FOREIGN_KEY_CHECKS=1');
}
}
我发现了。似乎在 .sql 文件中有一行说:
SET AUTOCOMMIT = 0;
文件末尾未设置回1。
我有一个尴尬的问题,每两次我 运行 php artisan migrate:refresh --seed
migrations
table 是空的,虽然它应该在迁移后添加初始迁移记录: 2018_05_02_114819_add_initial_migration
这是我的迁移代码(它是旧数据库模式的导入):
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInitialMigration extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('users')){
DB::unprepared(File::get(database_path('sam.sql')));
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0');
foreach (DB::select('SHOW TABLES') as $table) {
$table_array = get_object_vars($table);
if($table_array[key($table_array)] !== 'migrations'){
DB::statement('DROP TABLE ' . $table_array[key($table_array)]);
}
}
DB::statement('SET FOREIGN_KEY_CHECKS=1');
}
}
我发现了。似乎在 .sql 文件中有一行说:
SET AUTOCOMMIT = 0;
文件末尾未设置回1。