Worked fine for me as well. Thanks.
On Thursday, October 25, 2012 10:50:09 PM UTC+5:30, Jeremy Evans wrote:
>
> On Thursday, October 25, 2012 8:39:40 AM UTC-7, Jeremy Evans wrote:
>>
>> On Thursday, October 25, 2012 6:00:22 AM UTC-7, Kartik Rustagi wrote:
>>>
>>> Hi,
>>>
>>> I have a table A with a column 'abc' which I want to rename to 'xyz'.
>>> Column 'abc' being primary key. I have written the following migration to
>>> do so:
>>>
>>> *alter_table :A do*
>>> * rename_column(:abc, :xyz)*
>>> *end*
>>> *This migration fails with the error: ERROR 1068 (42000): Multiple
>>> primary key defined*
>>> *Mysql logs shows the query being: ALTER TABLE `A` CHANGE COLUMN `abc`
>>> `xyz` int(11) NOT NULL PRIMARY KEY*
>>>
>>>
>>> I reckon this is because we add 'PRIMARY KEY' constraint to alter table
>>> statement. How can I avoid this?
>>>
>>
>> The rename_column stuff on MySQL probably needs to be modified to not add
>> the PRIMARY KEY syntax. Would be nice if MySQL supported renaming columns
>> directly instead of attempting to emulate it with CHANGE COLUMN. You may
>> want to try this untested patch:
>>
>> diff --git a/lib/sequel/adapters/shared/mysql.rb
>> b/lib/sequel/adapters/shared/mysql.rb
>> index 5515a03..3114cdf 100644
>> --- a/lib/sequel/adapters/shared/mysql.rb
>> +++ b/lib/sequel/adapters/shared/mysql.rb
>> @@ -195,6 +195,7 @@ module Sequel
>> opts[:null] = o == :set_column_null ? op[:null] :
>> opts[:allow_null]
>> opts[:default] = o == :set_column_default ? op[:default] :
>> opts[:ruby_default]
>> opts.delete(:default) if opts[:default] == nil
>> + opts.delete(:primary_key) if op[:op] == :rename_column
>> "CHANGE COLUMN #{quote_identifier(op[:name])}
>> #{column_definition_sql(op.merge(opts))}"
>> when :drop_constraint
>> type = case op[:type]
>>
>> I'll test that later and see how it works.
>>
>
> This appears to work fine in my testing, so I've pushed it to GitHub.
>
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/vMtjivCBGewJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.