mysql数据库 text类型的长度限制,使用change_column来进行长度的修改并不影响原有数据

在我的概念中,mysql中的text字段应该是没有长度限制的,但是今天事实告诉我,text类型的长度是有限制的。其中mysql的text类型有64K长度限制的,MEDIUMTEXT中型是2G,LONGTEXT大型是4G .

Creating MEDIUMTEXT columns in MySQL using Rails

Adapted from http://www.depixelate.com/2008/5/24/rails-migrations-for-large-text-columns:

  create_table :foo do |t|
    ...
    t.text     :new_col, :limit => 64.kilobytes + 1
    ...
  end

Leave a CommentCreating MEDIUMTEXT columns in MySQL using Rails

Adapted from http://www.depixelate.com/2008/5/24/rails-migrations-for-large-text-columns:

  create_table :foo do |t|
    ...
    t.text     :new_col, :limit => 64.kilobytes + 1
    ...
  end

Leave a Comment

 

 

mysql text类型 长度不够的问题

2006-05-27  作者:amao  同分类文章 

description:

转一篇文章存入数据库只能显示全面一部分,

ALTER TABLE fib_blog CHANGE content content LONGTEXT NOT NULL

修改数据库,然后看看  .htaccess使用指南    利用这个来让blog静态化。就像bbs.chinahtml.com一样

1.1 Migrations are Classes

A migration is a subclass of ActiveRecord::Migration that implements two class methods: up(perform the required transformations) and down (revert them).

Active Record provides methods that perform common data definition tasks in a database independent way (you’ll read about them in detail later):

  • create_table
  • change_table
  • drop_table
  • add_column
  • change_column
  • rename_column
  • remove_column
  • add_index
  • remove_index

i found mysql text type has 64k limit,and for my application,it's not enough,so how to migrate from text to mediumtext,also i want keep my original data well

link|edit|close|delete|flag

add comment
alter table foo modify column bar mediumtext;
link|edit|flag
     change_column :urls,:content,:text,:limit=>128.kilobytes

  • change_column(table_name, column_name, type, options): Changes the column to a different type using the same parameters as add_column.

http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

http://guides.rubyonrails.org/migrations.html

ActiveRecord::Migration.upgrade_table :subtitles do |t|
t.integer :video_id, :null => false
end

这个方法写在rake里,以后就不用migration了,要不然文件太多了,是朋友教我的,呵呵

原文地址:https://www.cnblogs.com/lexus/p/1947940.html