如何在 Rails 应用程序中使用 script/generate 将列类型从 string 更改为 varchar?

发布于 2024-09-27 23:21:52 字数 191 浏览 2 评论 0原文

尝试将 Rails 应用程序的 sqlite3 数据库迁移到 mysql 数据库。名为“content”的列是sqlite3中的字符串类型。我想在mysql中将其更改为varchar(或者可能是文本)。我不确定是否有办法通过使用“ruby script/generate”命令来做到这一点。有什么想法吗?显然,我可以使用所需的列类型重新开始,但想知道是否有更好的方法。

Trying to migrate a sqlite3 db for a rails app to mysql db. The column named "content" was a string type in sqlite3. I want to change it to varchar (or perhaps text) in mysql. I am not sure if there is a way to do this by using "ruby script/generate" command. Any ideas? Obviously, I could start all over again with desired column types but wondering if there is a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨轻弹 2024-10-04 23:21:52

如果您在模式中将列类型定义为字符串,那么它在 mysql 中就已经是 VARCHAR。如果您想将其更改为文本字段,请使用 script/generate Migration ChangeModelxContentToText 之类的内容创建迁移,然后使用 change_column 进行更改。

If you've defined your column type as a string in your schema, then it will already be a VARCHAR in mysql. If you want to change it to a text field, create a migration using something like script/generate Migration ChangeModelxContentToText and then use change_column to change it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文