Rails:无法在迁移中使用 change_column 添加 :precision 或 :scale 选项? [英] Rails: Cannot add :precision or :scale options with change_column in a migration?

查看:28
本文介绍了Rails:无法在迁移中使用 change_column 添加 :precision 或 :scale 选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎已经被问过:rails小数精度和比例

但是当为 :precision:scale 运行 change_column 迁移时,它们实际上不会影响架构或数据库,但 db:migrate 运行没有错误.

But when running a change_column migration for :precision or :scale they don't actually affect the schema or database, but db:migrate runs without errors.

我的迁移文件如下所示:

My migration file looks like this:

class ChangePrecisionAndScaleOfPaybackPeriodInTags < ActiveRecord::Migration
  def self.up
    change_column :tags, :payback_period, :decimal, { :scale => 3, :precision => 10 }
  end

  def self.down
    change_column :tags, :payback_period, :decimal
  end
end

但我的架构(和数据)仍然是:

But my schema (and the data) remains as:

t.decimal  "payback_period"

其他人有这个问题吗?

谢谢,

乔什

推荐答案

不适用于 SQLite3

对于我正在运行的这个简单的测试应用程序,我设置了 SQLite3.显然,SQLite3 不依赖于列类型声明,并且更加动态,而是查看列的内容 - 在这里偶然发现:

Does Not Work for SQLite3

For this simple test app that I'm running I have SQLite3 setup. Apparently, SQLite3 doesn't rely on column type declarations and is more dynamic, looking at the column's content instead - as was stumbled upon here:

在 sqlite3 中修改列的类型

我尚未对其进行测试,但我确信这就是架构没有被更改的原因,因为 change_column 不会转换为 SQLite3 中的任何内容.

I haven't tested it but I'm sure that's why the schema wasn't being changed, because change_column doesn't translate to anything in SQLite3.

谢谢大家的回复.

这篇关于Rails:无法在迁移中使用 change_column 添加 :precision 或 :scale 选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆