不能在 DEFAULT 表达式 rails 迁移中使用列引用

问题描述 投票:0回答:2

错误:PG::FeatureNotSupported:错误:不能在 DEFAULT 表达式中使用列引用 LINE 1: ..._at" timestamp, "total" decimal DEFAULT (COALESCE(price, (0)...

class AddTotalToOrderLines < ActiveRecord::Migration[6.1]
def up
  execute <<~SQL
    ALTER TABLE order_lines
    ADD COLUMN total numeric GENERATED ALWAYS AS (COALESCE(price, 0) * 
    COALESCE(quantity, 0)) STORED;
  SQL
end
ruby-on-rails ruby postgresql rails-migrations
2个回答
0
投票

以防万一您认为自己快要疯了(或者某些 googler 发现了这一点),问题是如果您使用

GENERATED
,Rails 会将
DEFAULT
列语句转换为
schema.rb
语句。为了让它正常运行,您需要切换到
structure.sql
方法。


-1
投票

也许您有另一个实际产生错误的迁移。你展示的那个没有:)

© www.soinside.com 2019 - 2024. All rights reserved.