title: ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry
body: <p>I'm having the following error when trying to save an entry with the same URL and user_id. The issue here is that I need to add it but with a different provider (Yext, Synup or Default) (look at the very end of the ActiveRecordError). </p>
  
  <p>Below, I pasted the validations in my controller and the table indexes as well but I'm not sure if </p>
  
  <p>1) I need to remove the current index and add a new one with the <strong>provider</strong> column</p>
  
  <p>AND/OR</p>
  
  <p>2) change the validates in the controller to allow saving the records with same <strong>user_id, url but different provider</strong></p>
  
  <p><strong>Thanks for your answer!!</strong></p>
  
  <p>ActiveRecord Error:</p>
  
  <pre><code>#&lt;ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '1070078-https://www.cylex.ca/company/the-painted-window-wedding-' for key 'index_business_profiles_on_user_id_and_url': INSERT INTO `business_profiles` (`local_seo_site_id`, `url`, `success_at`, `company_location_id`, `provider`, `user_id`, `created_at`, `updated_at`) VALUES (136, 'https://www.cylex.ca/company/the-painted-window-wedding-venue-24052526.html', '2019-06-08 07:36:36', 1051892, 'synup', 1070078, '2019-06-08 07:36:36', '2019-06-08 07:36:36')&gt;
  </code></pre>
  
  <p>Validations:</p>
  
  <pre><code>validates :user_id, :local_seo_site_id, :url, presence: true
    validates_uniqueness_of :url, scope: [:user_id, :provider], case_sensitive: false, if: :url_changed?
    # vendor can't add same directory twice to same account
    validates_uniqueness_of :local_seo_site_id, scope: [:user_id, :admin_id, :company_location_id], on: :create, if: :added_by_vendor?
    validates :url, :url =&gt; true, if: :url_changed?
  </code></pre>
  
  <p>Table Index:</p>
  
  <pre><code>add_index :business_profiles, [:user_id, :url], unique: true
  </code></pre>