簡體   English   中英

MySQL遷移錯誤

[英]Mysql migration error

嘗試遷移數據庫時,出現以下錯誤。

 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)

正如我在上面的評論中指出的那樣, blobtext列不能具有默認值。 請參閱“ BLOB和TEXT類型

您需要按以下方式更改遷移:

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

更新:請注意,此遷移將descriptionoverview列類型更改為text

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM