【问题标题】:Laravel does not create a record in `migrations` table on refreshLaravel 不会在刷新时在“迁移”表中创建记录
【发布时间】:2018-11-02 01:44:37
【问题描述】:

我有一个尴尬的问题,每运行一次php artisan migrate:refresh --seedmigrations 表是空的,虽然它应该在迁移后添加初始迁移记录: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');
    }
}

【问题讨论】:

    标签: laravel eloquent laravel-migrations


    【解决方案1】:

    我发现了。似乎在 .sql 文件中有一行说:

    SET AUTOCOMMIT = 0;

    在文件末尾没有设置回 1。

    【讨论】:

    • 我本可以搜索很长时间,以为是 Laravel 错误,但 Google 搜索救了我。谢谢!
    猜你喜欢
    • 2014-02-18
    • 2017-05-07
    • 2019-01-21
    • 2015-11-24
    • 2018-10-26
    • 2016-10-23
    • 2015-03-28
    • 2015-01-14
    • 2018-04-20
    相关资源
    最近更新 更多