【问题标题】:Serializing long Array in MySQL text type field and increasing the size of text type.在 MySQL 文本类型字段中序列化长数组并增加文本类型的大小。
【发布时间】:2013-12-18 06:11:27
【问题描述】:

我创建了一个使用 MySQL DB 的 Rails 应用程序。我需要将一长串 ID 保存到通知表中的表字段(用户)之一。

+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Null | Key | Default | Extra          |
+------------+----------+------+-----+---------+----------------+
| id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| status     | int(11)  | YES  |     | 0       |                |
| message    | text     | YES  |     | NULL    |                |
| created_at | datetime | YES  |     | NULL    |                |
| updated_at | datetime | YES  |     | NULL    |                |
| users      | text     | YES  |     | NULL    |                |
+------------+----------+------+-----+---------+----------------+

所以在我的通知模型中:

class Notification < ActiveRecord::Base
  serialize :users, Array
end

现在的问题是我不能保存超过 ~64kb,很多用户没有保存。

我应该如何增加文本的大小?

【问题讨论】:

  • 好吧,看来诀窍是将类型更改为 mediumtext 使用: ALTER TABLE notifications MODIFY users MEDIUMTEXT ;
  • 发布您问题的答案。然后选择它作为答案。

标签: mysql sql ruby-on-rails serialization


【解决方案1】:

好吧,看来诀窍是将类型更改为 MEDIUMTEXT:

ALTER TABLE notifications MODIFY users MEDIUMTEXT

如果您使用的是 Rails,您可以通过更改限制选项在迁移文件中进行设置:

add_column :notifications, :users, :text, :limit => 16777215

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多