尝试迁移数据库时,我收到以下错误。
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)
答案 0 :(得分:1)
正如我在上面的评论中所指出的,blob
和text
列不能有默认值。请参阅“The BLOB and TEXT Types”
您需要更改迁移,如下所示:
change_table :habitat_version do |t|
t.change :description, :overview, :text
end
更新:请注意,此迁移会将description
和overview
的列类型更改为text
。