Rails / RSpec ActiveRecord :: RecordNotUnique:PG :: UniqueViolation:运行规范时出错

时间:2016-07-22 21:13:56

标签: ruby-on-rails postgresql rspec

我一直在谷歌上搜索我在Stackoverflow上找到的不同解决方案,但似乎无法找到解决方案。

我已经尝试过重新播放重新播放我的数据库.....我把postgres吹掉并重新安装......

试图通过rails控制台重启我的序列

 ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.reset_pk_sequence!(t) }

我尝试删除遇到问题的表并重新运行迁移......

 ActiveRecord::RecordNotUnique:
    PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_monthly_recordable_and_end_of_month_date"
    DETAIL:  Key (monthly_recordable_id, monthly_recordable_type, end_of_month_date)=(19, Actual, 2011-08-31) already exists.
    : INSERT INTO "monthly_records" ("monthly_recordable_type","monthly_recordable_id","end_of_month_date","end_of_quarter_date","actuals_import_batch_id","production","created_at","updated_at") VALUES ('Actual',19,'2011-08-31','2011-09-30',13,244.0,'2016-07-22 21:07:47.183392','2016-07-22 21:07:47.183402'),('Actual',19,'2011-07-31','2011-09-30',13,432.0,'2016-07-22 21:07:47.183392','2016-07-22 21:07:47.183402'),('Actual',19,'2011-06-30','2011-06-30',13,992.0,'2016-07-22 21:07:47.183392','2016-07-22 21:07:47.183402')RETURNING id

任何帮助都会受到赞赏......

该应用程序工作正常........但我不得不重新启动该项目并在此时开始重新设置

0 个答案:

没有答案