Rails 6没有保存到数据库



我试图将记录保存到rails模型。我使用postgres13数据库作为基础数据库。(遵循本教程:Stripe Webhooks教程)

当我运行代码时,返回id,如果我从控制台中查询模型,我可以看到所有记录。我在日志中没有得到任何错误。

问题是,它没有写入db表。这可能是什么原因,我该如何解决它?

我尝试这样保存数据:

event = WebhookEvent.create!(webhook_params)

webhook_params是这样的:

def webhook_params
{
source: params[:source],
data: params.except(:source, :controller, :action).permit!,
external_id: external_id
}
end

模型:

class WebhookEvent < ApplicationRecord
enum state: { pending: 0, processing: 1, processed: 2, failed: 3 }
end

和表定义:

class CreateWebhookEvents < ActiveRecord::Migration[6.0]
def change
create_table :webhook_events do |t|
t.string :source
t.string :external_id
t.json :data
t.integer :state, default: 0
t.text :processing_errors
t.timestamps
end
add_index :webhook_events, :source
add_index :webhook_events, :external_id
add_index :webhook_events, [:source, :external_id]
end
end

如有任何建议,不胜感激。

供参考。似乎是模型出了问题。我用一个不同的名字重新生成它,它工作得很好。

最新更新