Ruby on rails 迁移失败';未找到方法';用于添加数据库字段

Ruby on rails 迁移失败';未找到方法';用于添加数据库字段,ruby-on-rails,postgresql,rails-migrations,Ruby On Rails,Postgresql,Rails Migrations,我正在rails 6应用程序上运行大量迁移。当我进行迁移时,在尝试访问上一个迁移步骤中新添加的字段的特定属性时,它总是失败。失败后,我只需重新运行迁移,它就可以工作了,显然它可以在第二次找到属性。对这里可能发生的事情有什么想法吗 deleted_customer = Customer.new(first_name:"Deleted",last_name:"Deleted",active:false,customer_type_id:CustomerType.first.id) deleted_c

我正在rails 6应用程序上运行大量迁移。当我进行迁移时,在尝试访问上一个迁移步骤中新添加的字段的特定属性时,它总是失败。失败后,我只需重新运行迁移,它就可以工作了,显然它可以在第二次找到属性。对这里可能发生的事情有什么想法吗

deleted_customer = Customer.new(first_name:"Deleted",last_name:"Deleted",active:false,customer_type_id:CustomerType.first.id)
deleted_customer.save(validate:false)

StandardError: An error has occurred, this and all later migrations canceled: unknown attribute 'active' for Customer.
在一次失败之前的迁移中

add_column :customers, :active, :boolean, default: true

我遗漏了什么吗?

Rails在第一次访问模型时读取模式信息并缓存它(这样它就不必在每次访问模型时都读取db模式)

您可以重置该缓存:

Customer.connection.schema_cache.clear!
Customer.reset_column_information

完美的谢谢