mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.19k forks source link

Validation failed: Tag has already been taken error when try to upload a set of content with same tags #1048

Closed shah21 closed 2 years ago

shah21 commented 2 years ago
ActiveRecord::RecordInvalid:
       Validation failed: Tag has already been taken

Here is the test

RSpec.describe 'Repeat test' do
  it 'should create correct data' do
    for i in 1..10 do
      a = Article.new(title: "Article #{i}", reference_id: "A#{i}", language: 'english', country_code: 'IN')
      a.tag_list = ['tag1', 'tag2', 'tag3']
      a.save!
    end
  end
end

In the actual project, I was trying to upload a bulk of data. So I got this error

ttienism commented 2 years ago

I also ran into this error when trying to seed the local database. The actual problem was because the tables that I tried to add tags to use uuid, so regenerating ActsAsTaggableOn migration with this https://github.com/mbleigh/acts-as-taggable-on/issues/698 fixed this error for me. Hope it can help anyone that comes here.