【问题标题】:Devise primary key error on postgresql, heroku, Rails 4 [duplicate]在 postgresql、heroku、Rails 4 上设计主键错误 [重复]
【发布时间】:2023-03-27 08:00:02
【问题描述】:

真的很奇怪,我正在尝试通过命令行创建一个新用户,但我收到了这个错误:

User.create :email => "pheewq+1@gmail.com", :password => '123456789', :password_confirmation => '123456789'

PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "users_pkey"
DETAIL:  Key (id)=(37) already exists.

【问题讨论】:

    标签: ruby-on-rails postgresql heroku devise


    【解决方案1】:

    试试这个

    $ heroku run rails console
    irb(main)> ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.reset_pk_sequence!(t) }
    

    来源: https://stackoverflow.com/a/15108735/3034747

    【讨论】:

    猜你喜欢
    • 2016-04-07
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多