gpt4 book ai didi

mysql - Rails 单元测试中的枚举

转载 作者:行者123 更新时间:2023-11-29 13:34:16 25 4
gpt4 key购买 nike

我正在测试一些遗留代码。其中一个表有一个 enum 列。 (我知道,别恨,不是我写的)。

在尝试运行单元测试之前一切正常。突然,数据库架构将 enum 列保存为 varchar(0)。显然不允许我设置任何值。

这是我的大问题。如何向 rake test:units 添加 Hook 来调整列类型?它是 enum 还是只是 varchar(100) 并不重要。

谢谢!

最佳答案

所以这个问题的解决方案比我预想的要容易。在 environment.rb 文件中有一个部分:

# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

取消最后一行的注释意味着两件事。首先,模式以 SQL 而不是 Ruby 导出。其次,保留数据库特定的数据类型。

config.active_record.schema_format = :sql

关于mysql - Rails 单元测试中的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18959922/

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