Laravel 无需迁移

问题描述 投票:0回答:3

我使用命令

php artisan make:migration migration_name
php artisan make:model ModelName -mcr
在我的 Laravel 项目上创建了迁移。

当我运行

php artisan migrate
时,输出是
nothing to migrate
.

我检查我的数据库,只有

migration
表没有行,甚至没有创建来自Laravel的
user
表。

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

这是我使用 XAMPP 运行 Laravel 的环境

  • Laravel 7.24 和 Laravel 5.8.38
  • Apache/2.4.39 (Win64)
  • PHP 7.3.7
  • MariaDB 10.3.16
  • 作曲家 1.10.10

这是迁移代码

<?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. Run
    php artisan migrate:reset
    -> 没有什么可以回滚
  3. 运行
    php artisan migrate:fresh
    ->成功删除所有表,成功创建迁移表,没有要迁移的东西
  4. 运行
    php artisan migrate --path="/database/migrations/"
    -> 无需迁移
  5. 运行
    php artisan migrate:status
    -> 没有找到迁移
  6. 运行
    php artisan migrate:install
    -> 迁移表创建成功,但没有解决问题

TLDR

我真正做的是:

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

编辑

如果我用像

php artisan migrate --path="database/migrations/2020_08_11_064146_create_category_table.php"

这样的文件名完全指定路径,就可以运行迁移
php laravel laravel-5.8 laravel-7
3个回答
0
投票

This answer is not the best solution for such situation, but you can try to define migration path hard in

AppServiceProvider
:

/**
 * Register Custom Migration Paths
 */
$this->loadMigrationsFrom([
    database_path().DIRECTORY_SEPARATOR.'migrations'
]);/

0
投票

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

我的项目没有这些字符,但它有“奇怪”的字符,即左方括号和右方括号“[]”,所以我想改变它。

我的项目根目录路径是

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
    ,并期望迁移不会工作,但是迁移工作没有问题

0
投票

从路径中删除所有非字母数字字符 即你项目的路径应该是 c:/code/mylaravelproject

© www.soinside.com 2019 - 2024. All rights reserved.