Strange SQL issue with ApplicationRecord.destroy method

When I run this code:

@test = InstanceName.find_by(instance_number: "25", project_id: "4")
@test.destroy

The SQL query that Rails tries to execute is this:

DELETE FROM "instance_names" WHERE "instance_names"."" IS NULL

But the one it should be doing is this, right?

DELETE FROM instance_names WHERE instance_number = '25' AND project_id = '4'

Since it’s trying to execute the above, I always get the error: SQLite3::SQLException: no such column: instance_names.

Is this a bug, or what is going on?

Can you share your InstanceName model?

What is returned when you run this in a rails c?

InstanceName.primary_key

This was shared in r/rails as well. Sadly also without enough information to reproduce the error.

One of the causes might be a table without a primary key.