Laravel 没有要迁移的内容

Laravel Nothing to Migrate

我使用命令 php artisan make:migration migration_namephp artisan make:model ModelName -mcr 在我的 Laravel 项目上创建了迁移。

当我 运行 php artisan migrate 输出是 nothing to migrate.

我查了一下我的数据库,只有migration table没有行,连来自Laravel的user table也没有创建.

这个问题出现在我的笔记本电脑和 PC 上

这是我使用 运行 Laravel 使用 XAMPP

的环境

这是迁移代码

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

//File name = 2020_08_11_064146_create_category_table.php
//File Path = database/migrations

class CreateCategoryTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('category', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('category');
    }
}

我已经试过了,但没有成功:

  1. 运行 composer dump-autoload
  2. 运行 php artisan migrate:reset -> 无需回滚
  3. 运行 php artisan migrate:fresh-> 删除所有 table 成功,迁移 table 创建成功,没有要迁移的内容
  4. 运行 php artisan migrate --path="/database/migrations/" -> 无需迁移
  5. 运行 php artisan migrate:status -> 未找到迁移
  6. 运行php artisan migrate:install->迁移table创建成功,但没有解决问题

TLDR :

我的字面意思是:

  1. 使用 composer
  2. 下载 Laravel
  3. 编辑 .env 以使用用户 root
  4. 连接到数据库
  5. 使用 php artisan make:migration create_table_category
  6. 创建迁移
  7. 运行 php artisan migrate
  8. 结果 = Migration table create successfully, nothing to migrate。数据库只有 table migrations 没有行

编辑

迁移可以是 运行 如果我用文件名完全指定路径 php artisan migrate --path="database/migrations/2020_08_11_064146_create_category_table.php"

这个答案不是针对这种情况的最佳解决方案,但您可以尝试在 AppServiceProvider:

中硬定义迁移路径
/**
 * Register Custom Migration Paths
 */
$this->loadMigrationsFrom([
    database_path().DIRECTORY_SEPARATOR.'migrations'
]);/

我偶然发现了 this post,它描述了由带有字符连字符 '-' 的项目路径引起的问题

我的项目没有这些字符,但有 'weird' 个字符,即左方括号和右方括号 '[ ]',所以我想更改它。

我的根项目目录路径是F:\Indra\Kerja\[1] Personal\Personal profile\web所以我的迁移路径是F:\Indra\Kerja\[1] Personal\Personal profile\web\database\migrations

注意有一个名为 [1] Personal 的文件夹,这就是罪魁祸首

我将我的文件夹重命名为 Personal,瞧,迁移工作正常。

我很好奇,所以我尝试了不同的文件夹名称,我得到了有趣的结果:

  • [asdasd]Personal -> 由于某种原因迁移无效
  • [1 Personal->迁移工作
  • ]1Personal->迁移工作
  • ][1 Personal->迁移工作
  • []Personal -> 迁移工作

所以我必须更改我的文件夹名称

重要提示:

  • 我的操作系统是 Windows 10 Pro Version 1909 Build 18363.1082
  • 我也试过像这样在我的项目目录中添加连字符“-”F:\Indra\Kerja\my-project-test,预计迁移不会成功,但是迁移没有问题