Project

General

Profile

Actions

Defect #771

closed

rev1093 doesn't work: Fixed migration 87 (mysql: TEXT column can't have a default value).

Added by Chaoqun Zou about 16 years ago. Updated about 16 years ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
Start date:
2008-03-02
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

my enviroment is:
windows xp
rails 2.0.2
mysql 5.0.45
redmine r1183

in 001_setup.rb line174
create_table "projects", :force => true do |t|
t.column "name", :string, :limit => 30, :default => "", :null => false
t.column "description", :string, :default => "", :null => false
this means column "description" will have a default value of ""

and
in ruby\lib\ruby\gems\1.8\gems\activerecord-2.0.2\lib\active_record\connection_adapters\mysqladapter.rb line429
def change_column(table_name, column_name, type, options = {}) #:nodoc:
unless options_include_default?(options)
if column = columns(table_name).find { |c| c.name == column_name.to_s }
options[:default] = column.default
else
raise "No such column: #{table_name}.#{column_name}"
end
end
this means when use change_column in 087_change_projects_description_to_text.rb
change_column :projects, :description, :text, :null => true
active_record will find column description's default value and add it to the sql:
ALTER TABLE `projects` CHANGE `description` `description` text DEFAULT ''
which will fail, info:

rake aborted!
Mysql::Error: BLOB/TEXT column 'description' can't have a default value: ALTER TABLE `projects` CHANGE `description` `description` text DEFAULT ''

so I think just remove the "default => ''" statement from 087_change_projects_description_to_text.rb will not solve the problem.
Or should I use mysql5.1?

Actions #1

Updated by Michael Pirogov about 16 years ago

  • Assignee set to Jean-Philippe Lang

After an successfull migrate still got this:

Processing IssuesController#show (for 81.88.112.156 at 2008-03-03 11:27:05) [GET]
  Session ID: 523a1278c75bda26e60f67216b4f63ff
  Parameters: {"action"=>"show", "id"=>"77", "controller"=>"issues"}
Rendering templateissues/show.rhtmllayoutfalse within layouts/base
Rendering issues/show.rhtml

ActionView::TemplateError (undefined method `description' for #<Attachment:0xb6e543e8>) on line #4 of app/views/attachments/_links.rhtml:
1: <div class="attachments">
2: <% for attachment in attachments %>
3: <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%>
4: <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
5:   <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
6:   <% if options[:delete_url] %>
7:     <%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}),

    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/base.rb:1863:in `method_missing'

Actions #2

Updated by Chaoqun Zou about 16 years ago

  • Status changed from New to Resolved

to Michael:
I think your problem in issues controller is not the same question with my migration error.

to JP Lang:
I have resolved my migration error by some irregular method. Please note:
1. MySQL 5.0 and 5.1 will not allow default value for BLOB/TEXT column.
2. If MySQL is working in strict mode, it will report an error on a TEXT column's default value and stop. While if its work mode is not strict mode(maybe sql_mode=""), it will just give out a warning instead of an error and the sql command will be executed successfully.
3. MySQL 5.0 binary installed on windows will work in strict mode in default. While it will not work in strict mode on linux compiled from source.(I'm not sure with linux because I use windows xp)
4. So maybe most of the redmine's users wouldn't encounter this problem...

So, to windows users of redmine, if you have encountered my problem, there is a solution:
1. find your mysql server's ini file, will be "MySQL\MySQL Server 5.0\my.ini" in default.
2. locate this line: sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
3. add a "#" to the head: #sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
4. restart mysql server
5. run rake db:migrate, it should succeed this time
6. change the my.ini file back and restart mysql server

I'm sorry that I cann't find a more reasonable solution for this problem.

Actions #3

Updated by Jean-Philippe Lang about 16 years ago

  • Status changed from Resolved to Closed

Migration 87 is fixed by r1189.
It now runs fine with STRICT_TRANS_TABLES on.

Michael: I think you get this error because you didn't apply the migration 89 (the last one) which adds a description field to the attachments table.

Actions

Also available in: Atom PDF