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

Query builder keeps on using dropped column #45335

Closed
valentinomariotto opened this issue Dec 15, 2022 · 8 comments
Closed

Query builder keeps on using dropped column #45335

valentinomariotto opened this issue Dec 15, 2022 · 8 comments

Comments

@valentinomariotto
Copy link

  • Laravel Version: 9.41.0
  • PHP Version: 8.1.12
  • Database Driver & Version: RDS 8.0.mysql_aurora.3.02.0 and MariaDB 8 both

Description:

I dropped a column from one of my tables using the following migration script:

    public function up()
    {
        Schema::table('payouts', function (Blueprint $table) {
            $table->integer('authorized_by')->unsigned()->nullable()->after('paid_at');
            $table->dropColumn('paid');
        });
    }

Since then, I cannot reliably to update() or save() on the model.
I get the following error:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'paid' in 'field list' in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:566

The update() method never seem to work. The save() method sometimes works. But then it doesn't.

But of course the column "paid" appears NOWHERE in my model or my scripts. I also tried a full search in every folder, but nothing turned up. Example of a script that fails with the error above:

            $payout = Payout::findOrFail( $validated['payout_id'] );
            $payout->update([
                'paid_at'       => $payout->paid_at ?: Carbon::now(),
                'status'        => PayoutStatusEnum::Approved,
                'method'        => PayoutMethodEnum::from($validated['transfer_method']),
                'transaction_id'=> @$validated['transfer_reference'],
                'details'       => @$validated['details'],
                'authorized_by' => auth()->user()->id
            ]);

Clearing the cache has no effect.
Why does the query builder still use that column?

Steps To Reproduce:

I couldn't reproduce the problem on a different table, but the behavior is the same in dev and production.

@valentinomariotto
Copy link
Author

renaming App/Models/Payout.php to something else "solves" the issue for me

but I'd like to keep the original name..

@ankurk91
Copy link
Contributor

Are you sure "paid" columns no longer exists in the payouts table?
Check your mysql schema via mysql terminal.
+
If you are using op-cache, make sure to flush it properly.

FYI: Laravel pulls the table columns before firing the update query

protected function isGuardableColumn($key)

@driesvints
Copy link
Member

Thanks for helping @ankurk91.

I also often recommend to put any column renames or drops in a separate Schema::table( call as that's often the culprit. Anyway, please try a support channel if you need further help or feel free to continue the discussion here:

@valentinomariotto
Copy link
Author

Are you sure "paid" columns no longer exists in the payouts table? Check your mysql schema via mysql terminal. + If you are using op-cache, make sure to flush it properly.

FYI: Laravel pulls the table columns before firing the update query

protected function isGuardableColumn($key)

Of course I'm sure. Why would you think I opened an issue here?
Besides, the error says it cannot find the column in the DB.
And renaming the model solves the issue. And I can see with any DB tool that the column has been dropped.
So the problem is clearly on the laravel side, not on the db side.
There's some caching problem.

No, I'm not using OP-cache

@valentinomariotto
Copy link
Author

Thanks for helping @ankurk91.

I also often recommend to put any column renames or drops in a separate Schema::table( call as that's often the culprit. Anyway, please try a support channel if you need further help or feel free to continue the discussion here:

Do you mean a separate Schema::table() call when you use the dropColumn() method?

Maybe that should be documented

@valentinomariotto
Copy link
Author

I see the issue is closed, congratulations on fixing the bug so quickly

@ankurk91
Copy link
Contributor

This feature was introduced a long time ago
#33777

No one has reported such issue so far.

@valentinomariotto
Copy link
Author

that's not the issue

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

No branches or pull requests

3 participants