I have the following migration
class CreateBooking < ActiveRecord::Migration[5.1]
def change
create_table :bookings do |t|
t.integer :day_period, default: 0
t.references :service, foreign_key: true, unique: true, dependent: :destroy, index: true
end
end
end
and it generates the following schema:
create_table "bookings", force: :cascade do |t|
t.integer "day_period", default: 0
t.bigint "service_id"
t.index ["service_id"], name: "index_bookings_on_service_id"
end
When I run guard which runs a consistency_fail
test which fails with:
There are calls to has_one that aren't backed by unique indexes.
----------------------------------------------------------------
Model Table Columns
----------------------------------------------------------------
Service bookings (service_id)
----------------------------------------------------------------
Now originally I didn't have unique: true
but I rolled back and added it in, still the same problem, again, didn't have index: true
so I rolled back and added that in and still the same problem.
I think it's becuase service_id
in the schema doesn't have unique: true
on it but I don't know and I can't find any information on my specific problem.
What causes this problem, what am I doing that is causing this problem and what can I do to stop this problem, given the current migration?
t.references :service, foreign_key: true, dependent: :destroy, index: {unique: true}
More about creating references
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With