在PostgreSQL中强制字符串的最大长度

时间:2021-03-04 11:51:21

I am using heroku for a RoR application and am trying to manually set the length of a string column and am having trouble.

我正在为RoR应用程序使用heroku,并试图手动设置字符串列的长度,但遇到了麻烦。

I tried making a migration along the lines of

我试着沿着

change_column :posts, :content, :string, :length => 10000

I assumed this would work but no such luck, anyone have some pointers?

我想这是可行的,但没有这样的运气,有人有什么建议吗?

Thanks!

谢谢!

1 个解决方案

#1


78  

The length limit option in Rails migrations is called :limit:

Rails迁移的长度限制选项称为:限制:

change_column :posts, :content, :string, :limit => 10000

If you are finding yourself changing VARCHAR length limits a lot, you might want to read @depesz's blog post on VARCHAR vs TEXT.

如果你发现自己经常修改VARCHAR长度限制,你可能想看看@depesz关于VARCHAR vs TEXT的博客文章。

#1


78  

The length limit option in Rails migrations is called :limit:

Rails迁移的长度限制选项称为:限制:

change_column :posts, :content, :string, :limit => 10000

If you are finding yourself changing VARCHAR length limits a lot, you might want to read @depesz's blog post on VARCHAR vs TEXT.

如果你发现自己经常修改VARCHAR长度限制,你可能想看看@depesz关于VARCHAR vs TEXT的博客文章。