我有一个尴尬的问题,每次我运行php artisan migrate:refresh --seed
时migrations
表都是空的,尽管它应该在迁移后添加初始迁移记录: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');
}
}
答案 0 :(得分:0)
我发现了。似乎在.sql文件中有一行说:
SET AUTOCOMMIT = 0;
在文件末尾未将其设置回1。