Rails:无法在迁移中使用 change_column 添加 :precision 或 :scale 选项? [英] Rails: Cannot add :precision or :scale options with change_column in a migration?
问题描述
这似乎已经被问过: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:
我尚未对其进行测试,但我确信这就是架构没有被更改的原因,因为 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屋!