thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Overwriting `AddUserRoleRelationship` migration does not work? #3944

Closed iwasherefirst2 closed 4 years ago

iwasherefirst2 commented 5 years ago

Description:

I have installed Voyager with a separate user_admin table as described here: https://github.com/the-control-group/voyager/issues/2568

When I try to install my repository on a fresh database and call php artisan migrate I get this error: image

Additional context

Since I use a different user table, I had to overwrite a couple of the voyager migration files. like 2015_01_30_093900_create_voyager_users_table.php and 2016_01_01_000000_add_voyager_user_fields.php in my folder database/migrations.

Also, I had to create the file 2017_11_26_013050_add_user_role_relationship.php in my migrations folder and added the following:


class AddUserRoleRelationship extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('voyager_users', function (Blueprint $table) {
            $table->unsignedInteger('role_id')->change();
            $table->foreign('role_id')->references('id')->on('roles');
        });
    }

According to the migration logs the error that table users has no field role_id happens in 2017_11_26_013050_add_user_role_relationship.php. Now it is correct that the table users has no role_id. Instead this column may be found in the table voyager_users. It looks to me that the migration file is not executed from database/migrations but instead from vendor/tcg/ migrations/2017_11_26_013050_add_user_role_relationship.php:

class AddUserRoleRelationship extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->unsignedInteger('role_id')->change();
            $table->foreign('role_id')->references('id')->on('roles');
        });
    }

Why was I able to overwrite the migration file 2015_01_30_093900_create_voyager_users_table.php from voyager, but I am not able to overwrite 2017_11_26_013050_add_user_role_relationship.php ?

fletch3555 commented 5 years ago

Overriding migration files is a laravel feature (I wrote it), not a Voyager one, so I'm not sure why that would happen.

My only guess would be autoloaded classes cache. Try a composer dump-autoload then try again.

atsimerman commented 5 years ago

Any tips here? I faced the same issue. Clearing autoloaded classes cache didn't help.

MrCrayon commented 4 years ago

As @fletch3555 said overriding migrations is a Laravel feature, not much we can do here.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.