在Postgresql,heroku,Rails上设计主键错误4 [英] Devise primary key error on postgresql, heroku, Rails 4

查看:106
本文介绍了在Postgresql,heroku,Rails上设计主键错误4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

PG :: UniqueViolation:ERROR:重复键值违反唯一约束users_pkey
DETAIL:Key(id)=(37)已存在。


解决方案

尝试这个

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

资料来源:
http://stackoverflow.com/a/15108735/3034747


It is really odd, I'm trying to create a new user by command line and I'm getting this error:

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.

解决方案

Try This

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

Source: http://stackoverflow.com/a/15108735/3034747

这篇关于在Postgresql,heroku,Rails上设计主键错误4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆