【问题标题】:MySQL & Rails 4 - bundle exec rake db:migrate - Unsupported database for migration to UTF-8MySQL & Rails 4 - bundle exec rake db:migrate - 不支持数据库迁移到 UTF-8
【发布时间】:2015-03-10 16:14:37
【问题描述】:

我有一个从 Github 克隆的 Ruby on Rails 4 应用程序,我正在尝试在开发环境中的 MacBook 上启动和运行。

最初应用程序抱怨找不到 MySQL,所以我做了brew install mysql。我现在有mysqld 使用用户名root 运行并且没有密码并且应用程序能够连接到它,所以我通过了第一个驼峰。

不过,该架构尚未在数据库中构建 - 我可以在 db/migrate/ 目录中看到大约 115 个文件,其名称类似于 004_make_unicode_fiendly.rb016_add_asin_column.rb

我尝试运行bundle exec rake db:migrate,但前三个迁移文件显然运行成功后出现错误:

Migration error: Unsupported database for migration to UTF-8 support
/Users/jon/work/amazing_app/db/migrate/004_make_unicode_friendly.rb:22:in `alter_database_and_tables_charsets'
/Users/jon/work/amazing_app/db/migrate/004_make_unicode_friendly.rb:3:in `up'

运行mysqladmin variables | grep utf8 显示:

| character_set_client                               | utf8
| character_set_connection                           | utf8
| character_set_database                             | utf8
| character_set_results                              | utf8
| character_set_server                               | utf8
| character_set_system                               | utf8
| collation_connection                               | utf8_general_ci
| collation_database                                 | utf8_general_ci
| collation_server                                   | utf8_general_ci

我的问题:为什么会出现迁移错误?

【问题讨论】:

  • 您可以尝试运行 (bundle exec) rake db:create(如果尚未创建数据库),然后 rake db:reset?
  • 另外,如果这不是解决方案,能否请您提供 004_make_unicode_friendly.rb 文件,以便我们进一步查看(github gist 或 pastebin)
  • 谢谢 - 我刚刚按顺序发出了以下三个命令,现在似乎一切正常:bundle exec rake db:createbundle exec rake db:resetbundle exec rake db:migrate

标签: mysql ruby-on-rails-4 rake bundler dbmigrate


【解决方案1】:

如前所述回答: - 执行 (bundle exec rake) db:create, db:reset

这将使用您的种子和架构创建数据库,就像它们在另一台机器上一样。不知道具体的错误细节我无法评论您为什么首先收到错误(除非它说您无法迁移到 UTF-8,因为您已经使用 UTF-8) .

仅供参考,除非您现有的代码库有待处理的迁移,否则不需要 DB:Migrate。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 2012-04-08
    • 2012-04-18
    • 1970-01-01
    • 2012-01-07
    相关资源
    最近更新 更多