1

データベースを移行しようとすると、次のエラーが表示されます。

 Mysql2::Error: BLOB/TEXT column 'overview' can't have a default value: ALTER TABLE `habitat_versions` CHANGE `description` `overview` text DEFAULT '' NOT NULL

これを解決するために入力するコマンドを誰か教えてもらえますか?

移行の完全なコードは次のとおりです。

==  SplitHabitatDescriptionIntoIntroAndOverview: migrating ====================
-- rename_column(:habitat_versions, :description, :overview)
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: BLOB/TEXT column 'overview' can't have a default value: ALTER TABLE `habitat_versions` CHANGE `description` `overview` text DEFAULT '' NOT NULL
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:484:in `rename_column'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:in `method_missing'
/Users/webteam/wwf/db/migrate/20120523150123_split_habitat_description_into_intro_and_overview.rb:3:in `up'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block in migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `call'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `ddl_transaction'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `block in migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/webteam/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
4

1 に答える 1

1

上記のコメントで指摘したようにblobtext列にはデフォルト値を設定できません。「 BLOB および TEXT タイプ」を参照してください。

次のように移行を変更する必要があります。

change_table :habitat_version do |t|
  t.change :description, :overview, :text
end

description更新: この移行により、列の種類がとoverviewに変更されることに注意してくださいtext

于 2013-08-08T16:59:48.440 に答える