2

Looking at Q A migration to add unique constraint to a combination of columns

In my migration file I already have a 'MobileDeviceRecord' table with an 'ActivationCode' which is created in code from a GUID class when a new record is created. I want to ensure the new 'ActivationCode' is unique to the existing 'ActivationCodes' in the table. Do I need to remove the 'ActivationCode' column and re-add it with a constraint or can I use an add_index...Also what is the proper way to use it??

public int UpdateFrom82()
    {
        add_index :MobileDeviceRecord, [:ActivationCode], :unique => true
        return 83;
    }
Community
  • 1
  • 1
John
  • 3,965
  • 21
  • 77
  • 163
  • I believe the reason you can't set this using AlterColumn is that it won't be able to guarantee the content in that column is already unique. As far as I know there's no fancy method allowing you to do this only if the content is already unique. – Søren Ullidtz Oct 24 '14 at 07:02

0 Answers0