ruby on rails - Seeding SQLite with Devise Model Gives Uniqueness Constraint Error -
edit stupid mistake:
db:reset seeds database.
i'm trying seed db , create users have posts users keep violating uniqueness constraint...even if there's 1 of them.
at moment, have no model validations.
the standard user devise schema:
create_table "users", force: :cascade |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "username" end add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true db/seeds.rb
1.times |n| email = faker::internet.email username = faker::name.name password = 'password' password_confirmation = 'password' reset_password_token = nil id = n user.create!( email: email, username: username, password: password, password_confirmation: password_confirmation, reset_password_token: reset_password_token, id: id ) end i have run following:
rails c rake db:reset rake db:migrate rake db:seed >> activerecord::recordnotunique: sqlite3::constraintexception: unique constraint failed: users.id: insert "users" i have single user generated violates uniqueness. stack trace tells me problem create method i'm not sure how remedy this.
i have 2 possible things need unique @ db level , that's index_users_on_email , index_users_on_reset_password both of unique if db has been reset , seeded 1 record.
where going wrong?
here how created seed users, hope helps.
1.times user = user.new( name: faker::name.name, email: faker::internet.email, password: faker::lorem.characters(10) ) user.skip_confirmation! user.save! end users = user.all
Comments
Post a Comment