ruby-on-rails ActiveRecord::StatementInvalid:错误提示:未知排序规则:'utf8_0900_ai_ci'

0yycz8jy  于 2023-10-21  发布在  Ruby
关注(0)|答案(3)|浏览(141)

我是一个新手,试图通过使用ROR版本5.0和mysql 8.02跟随Lynda视频系列学习ruby on rails。在DB> migrate> model. rb文件中创建表条目并运行"rails db:migrate"后,我在终端中得到一个错误,这没有太大意义。iv使用不同的用户和光栅它mysql特权和搜索在网上,但没有运气。

class Username <ActiveRecord::Migration [5.0]
def up create_table:用户做|不|

t.column "first_name", :string, :limit => 25
    t.string "last_name", :limit => 50
    t.string "email", :default => '', :null => false
    t.string "password", :limit => 40

  t.timestamps
end


def down

drop_table :users

结束

MBP:simple_cms $rails db:migrate rails aborted! ActiveRecord::StatementInvalid:错误提示:未知排序规则:'utf8_0900_ai_ci':CREATE TABLE schema_migrationsversion varchar(255)COLLATE utf8_0900_ai_ci PRIMARY KEY)ENGINE = InnoDB/Users/. rvm/gems/ruby-2.3.0/gems/mysql2 - 0.4.9/lib/mysql2/client. rb:一百二十:在查询"/Users/"中的_query' /Users/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.9/lib/mysql2/client.rb:120:in块中。rvm/gems/ruby-2.3.0/gems/mysql2 - 0.4.9/lib/mysql2/client. rb:一百一十九:在handle_interrupt' /Users/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.9/lib/mysql2/client.rb:119:in query '/Users/中。rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_mysql_adapter。rb:二百一十八:在log '/Users/中block in execute' /Users/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:590:in块中。rvm/gems/ruby-2.3.0/gems/activesupport-5.0.6/lib/active_support/notifications/instrumenter。rb:二十一:在instrument' /Users/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:583:in log '/Users/中。rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_mysql_adapter。rb:二百一十八:在execute' /Users/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/mysql/database_statements.rb:31:in中执行"/Users/。rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/schema_statements。rb:二百七十八:在create_table' /Users/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:423:in create_table '/Users/中。rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/schema_migration. rb:二十七:在create_table' /Users/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:1008:in initialize_schema_migrations_table'中

wswtfjt7

wswtfjt71#

有一个问题与您的问题有关:https://github.com/rails/rails/issues/28730
这个问题在rails v5.1.0.rc2中得到了解决。升级到最新版本并重新生成schema.rb应该可以消除您的问题。

eufgjt7s

eufgjt7s2#

如果utf8_0900_ai_ci不工作,也可以将通用collation添加到database.yml

development:
  adapter: mysql2
  ...
  encoding: utf8
  collation: utf8_general_ci
r6hnlfcb

r6hnlfcb3#

对于那些不能升级到rails v5.1.0.rc2,并且将collation添加到database.yml不起作用的人,应该在数据库级别修改排序规则。
在mysql控制台中运行以下命令:

ALTER DATABASE <database_name> CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci;

相关问题