Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

morph key column type should not be fixed to unsigned big integer #1172

Open
eidng8 opened this issue May 18, 2018 · 0 comments
Open

morph key column type should not be fixed to unsigned big integer #1172

eidng8 opened this issue May 18, 2018 · 0 comments

Comments

@eidng8
Copy link

eidng8 commented May 18, 2018

  • Laravel Version: 5.6.17
  • PHP Version: 7.1
  • Database Driver & Version: MySQL 5.6

Description:

Just migrated to Laravel 5.6, and found that morph methods in Schema\Blueprint have been changed to use unsigned big integer: morphs() & nullableMorphs by commit.

This change breaks a lot! And I don't think it could be easy or reasonable to change existing system for this. If this change has to be kept, it should provide a parameter to determine the type of column to be used.

To my case, the related columns of the morph targets are all auto increment unsigned integer primary key columns. I don't want to bring the INT vs BIGINT auto increment primary key argument here. The short answer is we can't change those primary keys to BIGINT.

My current work around is changing our migrations to alter the column type right after the Schema::create() call, and adds foreign key afterward.

        Schema::table(
            'a_morph_table',
            function (Blueprint $table) {
                DB::query('ALTER TABLE ....');
                $table->foreign('model_id', 'fk_to_other_primary_key_columns')
                    ->references('id')
                    ->on('target_table');
            }
        );

Originally posted on laravel/framework#23935

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant