From aa6d616d69e1e099d09472ddfce039659b4fd276 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 29 Jan 2011 17:23:12 +0100 Subject: [PATCH] db: person_id can only be updated if index is updated too. This fixes the following error: Mysql2::Error: Duplicate entry '0' for key 'index_profiles_on_person_id': ALTER TABLE `profiles` CHANGE `person_id` `person_id` int(11) NOT NULL --- db/migrate/20110127000953_make_fields_not_null.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20110127000953_make_fields_not_null.rb b/db/migrate/20110127000953_make_fields_not_null.rb index 343764f65..6a4fe84e5 100644 --- a/db/migrate/20110127000953_make_fields_not_null.rb +++ b/db/migrate/20110127000953_make_fields_not_null.rb @@ -20,11 +20,13 @@ class MakeFieldsNotNull < ActiveRecord::Migration end def self.up + remove_index(:profiles, :person_id) non_nullable_fields.each_pair do |table, columns| columns.each do |column| change_column_null(table, column, false) end end + add_index :profiles, :person_id end def self.down