Closed michaelhiiva closed 3 years ago
Adds find_or_create_by to create keys if not a record cannot be found. This will fix the error from $ rails db:test:prepare.
find_or_create_by
$ rails db:test:prepare
shell> $ RAILS_ENV=test bin/rails db:seed rails aborted! ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_years_on_year" DETAIL: Key (year)=(2011) already exists. /home/michael/projects/usgo/development/gocongress-earthschlange/db/seeds.rb:2:in `<main>' bin/rails:4:in `<main>' Caused by: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_years_on_year" DETAIL: Key (year)=(2011) already exists. /home/michael/projects/usgo/development/gocongress-earthschlange/db/seeds.rb:2:in `<main>' bin/rails:4:in `<main>' Tasks: TOP => db:seed (See full trace by running task with --trace)
Looks good -- thanks, Michael!
Summary
Adds
find_or_create_by
to create keys if not a record cannot be found. This will fix the error from$ rails db:test:prepare
.Error