Search code examples
phplaravellaravel-5.8laravel-7

Laravel Nothing to Migrate


I created migration on my Laravel project using command php artisan make:migration migration_name and php artisan make:model ModelName -mcr.

When I run php artisan migrate the output is nothing to migrate.

I check my database, there is only migration table which has no row, even user table that comes from Laravel does not created.

This issue occurs on my laptop and PC

This is the environment that I use to run Laravel using XAMPP

  • Laravel 7.24 and Laravel 5.8.38
  • Apache/2.4.39 (Win64)
  • PHP 7.3.7
  • MariaDB 10.3.16
  • Composer 1.10.10

This is the migration code

<?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');
    }
}

I already try these but found no luck :

  1. Run composer dump-autoload
  2. Run php artisan migrate:reset -> nothing to rollback
  3. Run php artisan migrate:fresh-> dropped all table successfully, migration table created successfully ,nothing to migrate
  4. Run php artisan migrate --path="/database/migrations/" -> nothing to migrate
  5. Run php artisan migrate:status -> no migrations found
  6. Run php artisan migrate:install -> Migration table create successfully, but did not solve the problem

TLDR :

What I literally did are :

  1. Download Laravel with composer
  2. Edit .env for connection to database using user root
  3. Create migration using php artisan make:migration create_table_category
  4. Run php artisan migrate
  5. Result = Migration table create successfully, nothing to migrate. Database only have table migrations with no rows

EDIT

Migration can be run if I specify the path completely with file name like php artisan migrate --path="database/migrations/2020_08_11_064146_create_category_table.php"


Solution

  • I stumbled into this post which described that the problems caused by project path that have character hyphens '-'

    My project does not have those characters, but it has 'weird' characters and that is opening and closing square bracket '[ ]', so I thought to change it.

    My root project directory path is F:\Indra\Kerja\[1] Personal\Personal profile\web so my migration path is F:\Indra\Kerja\[1] Personal\Personal profile\web\database\migrations

    Notice there's folder named [1] Personal, that's the culprit

    I renamed my folder to Personal and voila the migration works normally.

    I was curious so I try different folder name and I get and interesting result:

    • [asdasd]Personal -> migration doesn't work for some reason
    • [1 Personal-> migration work
    • ]1Personal-> migration work
    • ][1 Personal-> migration work
    • []Personal -> migration work

    So I have to change my folder name

    Important Note:

    • My Operating system is Windows 10 Pro Version 1909 Build 18363.1082
    • I also tried to give hyphens '-' to my project directory like this F:\Indra\Kerja\my-project-test, and expect that the migration won't work, but the migration works without a problem