Skip to content

[Bug] The migration are ran even if table already exists #14

@mathias-aa

Description

@mathias-aa

Use case :
You have a lot of migration files and to sanitize your migration folder you use the "php artisan schema:dump --prune" command to write all you migrations in an sql dump file.

After installing the package, when i run : "php artisan migrate:fresh --seed", i have an error saying that the table "file_system_items" already exists:

Image

The fix is to add a condition to the migration file :

if(!Schema::hasTable('file_system_items')) {
            // The "file_system_items" table do not exists exists...
            Schema::create('file_system_items', function (Blueprint $table) {
                $table->id();
                $table->foreignId('parent_id')->nullable()->constrained('file_system_items')->cascadeOnDelete();
                $table->string('name');
                $table->string('type');
                $table->string('file_type')->nullable();
                $table->unsignedBigInteger('size')->nullable();
                $table->unsignedInteger('duration')->nullable();
                $table->string('thumbnail')->nullable();
                $table->string('storage_path')->nullable();
                $table->timestamps();

                $table->index('type');
                $table->index('file_type');
                $table->unique(['parent_id', 'name']);
            });
        };

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions