我目前正在将 Rails ( 4.2.0
) 与 MySQL 一起使用。
我想用我的 Rails 应用程序设置 MemSQL。
我按照教程让 MemSQL 在 docker 容器内的 OSX 上运行。它工作正常。
我已经在我的database.yml
.
我成功地跑了rake db:create
。
但是,在运行时rake db:migrate
,我收到以下错误:
> rake db:migrate
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Distributed tables must either have a PRIMARY or SHARD key. Visit http://docs.memsql.com/4.0/concepts/porting-apps/ for more information: CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
Mysql2::Error: Distributed tables must either have a PRIMARY or SHARD key. Visit http://docs.memsql.com/4.0/concepts/porting-apps/ for more information
我想我可以以某种方式编辑db/schema.rb
文件并尝试更改schema_migrations
表格。但是 id 似乎不是一个好的解决方案,因为每次我更新表时都会重新生成它。
我应该怎么做才能解决这个问题?
编辑
此错误发生在全新的 Rails 项目中。
我做了以下事情:
- 创建一个新的 Rails 项目
- 添加 mysql2 宝石
- 将database.yml配置为memsql ip
- 添加设计宝石
- 用设计添加用户表
- 耙分贝:创建
- rake db:migrate(下面这个命令的结果)
schema.rb 的内容
ActiveRecord::Schema.define(version: 20150729143850) do
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
编辑二
这个问题更多是针对 Rails 开发人员而不是 MemSQL 专家。
- MemSQL 需要它处理的每个表的主键或分片键。
- 但是 Rails 没有为其schema_migrations
表定义一个。
这个问题给我带来了以下问题:
如何调整 Rails 让它为其schema_migrations
表定义主键或分片键?