更改列的 Rails 迁移

编程入门 行业动态 更新时间:2024-10-28 02:35:38
本文介绍了更改列的 Rails 迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有 script/generate migration add_fieldname_to_tablename fieldname:datatype 语法用于向模型添加新列.

We have script/generate migration add_fieldname_to_tablename fieldname:datatype syntax for adding new columns to a model.

在同一行上,我们是否有用于更改列数据类型的脚本/生成?或者我应该将 SQL 直接写入到我的 vanilla 迁移中吗?

On the same line, do we have a script/generate for changing the datatype of a column? Or should I write SQL directly into my vanilla migration?

我想将一列从 datetime 更改为 date.

I want to change a column from datetime to date.

推荐答案

我认为这应该可行.

change_column :table_name, :column_name, :date

更多推荐

更改列的 Rails 迁移

本文发布于:2023-10-17 22:06:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!