gpt4 book ai didi

ruby-on-rails - PG::InvalidDatetimeFormat:错误:类型日期的输入语法无效: “”

转载 作者:行者123 更新时间:2023-11-29 12:35:58 31 4
gpt4 key购买 nike

数据库postgresql

我有以下迁移:

class AlterBirthdayInUsers < ActiveRecord::Migration[5.0]
def change
change_column :users, :birthday, 'date USING CAST(birthday AS date)', default: Date.today
end
end

迁移启动错误:

rake stdout: == 20170201162913 AlterBirthdayInUsers: migrating =======================
-- change_column(:users, :birthday, "date USING CAST(birthday AS date)", {:default=>Sat, 18 Feb 2017})
rake stderr: rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type date: ""
: ALTER TABLE "users" ALTER COLUMN "birthday" TYPE date USING CAST(birthday AS date)

postgrees 如何在日期类型的迁移字段中更正点?

预先感谢您的回复。

最佳答案

它可能无法尝试将空字符串转换为日期,改变

USING CAST(birthday AS date) 

USING CAST(case when birthday = '' then null else birthday end AS date)

关于ruby-on-rails - PG::InvalidDatetimeFormat:错误:类型日期的输入语法无效: “”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42392052/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com