Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6142797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:26:15+00:00 2026-05-23T18:26:15+00:00

I have the following migration: class UniqueIndexOnCustomValueKeys < ActiveRecord::Migration def self.up add_index :custom_values, [:customizable_id,

  • 0

I have the following migration:

class UniqueIndexOnCustomValueKeys < ActiveRecord::Migration
  def self.up
    add_index :custom_values, [:customizable_id, :customizable_type, :custom_definition_id], {:unique=>true,:name=>:cv_unique_composite} 
  end

  def self.down
    remove_index :custom_values, :cv_unique_composite
  end
end

When I run the migration, it creates the UNIQUE key properly in the development database, but when I look at schema.rb, the :unique flag isn’t there. This is causing the test database to not have the UNIQUE index.

The resulting line in schema.rb looks like:

add_index "custom_values", ["customizable_id", "customizable_type", "custom_definition_id"], :name => "cv_unique_composite"

Am I doing something wrong here?

(Rails 3.0.8, MySql2 gem)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:26:16+00:00Added an answer on May 23, 2026 at 6:26 pm

    In order to accommodate unique indexes, you need to change the active_record.schema_format in application.rb:

    config.active_record.schema_format = :sql
    

    This will force the test database to use db/development_structure.sql which takes raw sql statements from the database instead of ruby commands.

    This question addresses Oracle, but the same issue exists for other database specific issues (In this case MySql Unique Indexes): Why am I not getting any index defintions in my Rails schema.db – "# unrecognized index …"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have the following migration class AddStatusField < ActiveRecord::Migration def self.up add_column
I have the following ActiveRecord migration: class CreateSubjects < ActiveRecord::Migration def self.up create_table :subjects
I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have the following 2 tables defined in migrations class CreateUsers < ActiveRecord::Migration def
I have an ExpenseType object that I have created with the following migration: class
I have the following many-to-many relationship: class Assignment < ActiveRecord::Base belongs_to :programmer belongs_to :project
I have the following class Item < ActiveRecord::Base end class Talk < Item end
I have a class similar to the following: class FruitKinds < ActiveRecord::Base Apple =
I have the following models: class Instance < ActiveRecord::Base has_many :users has_many :books end
I have the following migration and I want to be able to check if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.