После выгрузки, загрузки и pg_restoring DB из Heroku, каждый раз, когда я пытаюсь войти в свое приложение rails, я получаю вышеуказанную ошибку.
Почему-то кажется, что идентификатор пользователя выглядит как ноль (хотяЯ вижу значение идентификатора в БД).
Я также читал, что это может быть связано с тем, что идентификатор является простым целым числом вместо последовательного, как вы можете видеть в моей схеме:
create_table "users", id: :serial, force: :cascade do |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 "name"
t.string "last_name"
t.string "provider"
t.string "uid"
t.boolean "admin", default: false, null: false
t.boolean "affiliate_approved", default: false, null: false
t.integer "cart_id"
t.float "rev_share"
t.boolean "notice", default: false, null: false
t.string "iban"
t.string "piva"
t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
t.datetime "invitation_accepted_at"
t.integer "invitation_limit"
t.string "invited_by_type"
t.integer "invited_by_id"
t.integer "invitations_count", default: 0
t.string "username"
t.string "slug"
t.integer "enrolls_count", default: 0
t.integer "partner_id"
t.string "country"
t.integer "referrer"
t.boolean "gdpr_marketing"
t.boolean "privacy_policy"
t.boolean "subscription", default: false
t.date "account_created_at"
t.boolean "profilazione"
t.boolean "terms_and_conditions"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["invitations_count"], name: "index_users_on_invitations_count"
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["username"], name: "index_users_on_username", unique: true
end
И кажется, что идентификатор уже используется в качестве последовательного.
Есть ли у вас какие-либо идеи о том, что может быть не так?Это приложение работает в реальном времени с парой тысяч пользователей, которые не подвержены этой проблеме, из-за чего я думаю, что что-то не так с моей локальной настройкой PG.
Edit - полное сообщение об ошибке
PG::NotNullViolation at /auth/google_oauth2/callback
ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, 9367, 127.0.0.1, 2018-09-17 09:51:59.463125, 2018-09-17 09:51:59.463125).
Редактировать - больше результатов
В user.rb (файл модели) есть хук after_update, где выполняется следующее:
def change_log
UserChange.create(ip_request: current_sign_in_ip, user: self)
end
Это так, что мы можем отслеживать все, что пользователь меняет вместе с его IP (причины GDPR).
После комментирования все работает нормально, и мой пользователь входит в систему, как и планировалось