plank / laravel-mediable

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel
MIT License
773 stars 101 forks source link

Error: Cannot declare class CreateMediableTables During Migration in Laravel 11 Application #357

Closed nanaaikinson closed 2 months ago

nanaaikinson commented 4 months ago

I encountered an error while running php artisan migrate in a fresh Laravel 11 application after installing and setting up this package. The error message was: Cannot declare class CreateMediableTables, because the name is already in use.

I renamed all the migration classes published by the package to anonymous classes using the following format

return new class extends Migration {
    // Migration code here
};

The are multiple migrations being run

2016_06_27_000000_create_mediable_tables
2020_10_12_000000_add_variants_to_media
2024_03_30_000000_add_alt_to_media
2024_07_02_070806_create_mediable_tables
 2024_07_02_070807_add_variants_to_media

Any insights or suggestions to resolve this issue would be greatly appreciated. Thank you!

serotonie commented 4 months ago

Just delete the migrations files in database/migrations. They shouldn't be published with the config as they are auto-discovered by laravel when migrating (that's what I understand anyway).

nanaaikinson commented 4 months ago

Just delete the migrations files in database/migrations. They shouldn't be published with the config as they are auto-discovered by laravel when migrating (that's what I understand anyway).

Shouldn't it be best for users to publish the migrations and alter them (in my case, I use string-based IDs) instead of auto migration?

serotonie commented 4 months ago

Just delete the migrations files in database/migrations. They shouldn't be published with the config as they are auto-discovered by laravel when migrating (that's what I understand anyway).

Shouldn't it be best for users to publish the migrations and alter them (in my case, I use string-based IDs) instead of auto migration?

Indeed :)

Have a look a the config file, you have a ignore_migrationsthat should solve your issue

nanaaikinson commented 2 months ago

Just delete the migrations files in database/migrations. They shouldn't be published with the config as they are auto-discovered by laravel when migrating (that's what I understand anyway).

Shouldn't it be best for users to publish the migrations and alter them (in my case, I use string-based IDs) instead of auto migration?

Indeed :)

Have a look a the config file, you have a ignore_migrationsthat should solve your issue

Worked. Thanks