-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
error in Rails/UniqueValidationWithoutIndex #214
Comments
Thanks for the feedback. Can you show me db/schema.rb? |
@koic: I get the same error. In my case, it is due to a table that only has a primary key (no other columns). Here is the relevant part of the create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t|
end |
That particular model is not in the schema. I originally hit this bug with a model called create_table "building_locations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.integer "building_id", null: false
t.string "name", null: false
t.integer "building_floor_plan_id"
t.decimal "latitude", precision: 16, scale: 13
t.decimal "longitude", precision: 16, scale: 13
t.string "map_type"
t.string "map_file_name"
t.binary "map_data", limit: 16777215
t.text "notes"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["building_floor_plan_id"], name: "index_building_locations_on_building_floor_plan_id"
t.index ["building_id", "name"], name: "index_building_locations_on_building_id_and_name", unique: true
end I also hit it on a model called device with the following validates line: validates :management_ip, format: { with: Resolv::IPv4::Regex }, uniqueness: true,
allow_nil: true, if: :management_ip_changed? |
Apologies @seandilda, I didn't mean to overtake this issue – just got overly excited that someone posted about the issue I was having, minutes before I went looking for it. You seem to have a completely different bug than me. |
@FraDim no worries. Its still possible they're the same underlying issue. |
Fixes rubocop#214. This PR fixes an error for `Rails/UniqueValidationWithoutIndex` when a table has no column definition.
I reproduced the error and opened PR #218. Thank you! |
Fixes rubocop#214. This PR fixes an error for `Rails/UniqueValidationWithoutIndex` when a table has no column definition.
…hout_index [Fix #214] Fix an error for `Rails/UniqueValidationWithoutIndex`
Expected behavior
To not raise an exception
Actual behavior
Here's the backtrace generated by running
rubocop -d <filename>
:Steps to reproduce the problem
Here's the sample model I'm using:
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:The text was updated successfully, but these errors were encountered: