Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : dropForeignIdFor method in Blueprint.php #45134

Closed
wants to merge 1 commit into from
Closed

fix : dropForeignIdFor method in Blueprint.php #45134

wants to merge 1 commit into from

Conversation

anilkumarthakur60
Copy link

@anilkumarthakur60 anilkumarthakur60 commented Nov 29, 2022

577b84d

    public function dropForeignIdFor($model, $column = null)
    {
        if (is_string($model)) {
            $model = new $model;
        }

         $this->dropForeign([$column ?: $model->getForeignKey()]);
        return  $this->dropColumn($column ?: $model->getForeignKey());
    }

previously while adding new migation for existing table that reference some other table in the drop section of migration it only drops the key constrained but not column so each time to drop the column i have to add


    public function up(): void
    {
        Schema::table('tableName', function (Blueprint $table) {
         
            $table->foreignIdFor(\App\Models\User::class)->constrained();
           
        });
    }


    public function down(): void
    {
        Schema::table('tableName', function (Blueprint $table) {
            $table->dropForeignIdFor(\App\Models\User::class);
           $table->dropColumn(['user_id']);


            //
        });
    }

this only drops the key constrained not column so to overcome this issue
i have pf with changes in #577b84d

@ankurk91
Copy link
Contributor

Please link to the original issue in PR description.

@anilkumarthakur60
Copy link
Author

i have updated in description please recheck

@ankurk91
Copy link
Contributor

@anilkumarthakur60 There are failing tests, you may want to update them as well.
https://github.com/laravel/framework/actions/runs/3571042594/jobs/6002566923

@driesvints
Copy link
Member

Seems this breaks the test suite. Please resubmit this with passing tests.

@driesvints driesvints closed this Nov 29, 2022
@rodrigopedra
Copy link
Contributor

Isn't Blueprint@dropConstrainedForeignIdFor already there to cover this case?

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

Successfully merging this pull request may close these issues.

4 participants