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

 

1 Answer

 

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了,要不然文件太多了,是朋友教我的,呵呵

posted on 2011-01-30 17:17  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2011/01/30/1947940.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值