为什么 PostgreSQL 会回滚我的 INSERT 语句?

发布于 2024-11-29 18:18:39 字数 1711 浏览 2 评论 0原文

我有一个用来存储东西的模型。当布尔属性 (action_type) 的值为 false 时,PostgreSQL 会出于某种原因回滚 INSERT 查询。

create_table :process_flows do |t|
      t.integer :campaign_id
      t.integer :position
      t.string :description
      t.string :typestr
      t.float :action_number
      t.boolean :action_type
      t.string :action_on_donation
      t.integer :created_by
      t.integer :updated_by
      t.timestamps
end

我的视图文件如下所示:

<%= form_for [@org, @campaign, @process_flow] do |f| %>
        <%= render "shared/errors", :target => @process_flow %>
        <div class="field">
            <%= f.label :description %><br />
            <%= f.text_field :description %>
        </div>
        <div class="field">
            <%= f.label :typestr, 'Type of organization' %><br /><br />
            <%= f.select :typestr, options_for_select([["Point of collection", "PC", :selected => true], ["Your Organization", "O"], ["Bank / Payment Gateway", "B"], ["Intermediary", "I"], ["Recipient Charity Project", "R"]]) %><br /><br />
        </div>
        <%= f.select :action_on_donation, options_for_select([["100% (Unchanged)", "U", :selected => true], ["Increase", "A"], ["Decrease", "S"]]) %>
        the donation 
        by
        <%= f.text_field :action_number, :style=>"width: 30px;", :value => '0' %>
        <%= f.select :action_type, options_for_select([["Percent", '1', :selected => true], ["Flat Amount", '0']]) %>
        <div>
            <%= f.submit 'Add', :class=>'button' %>
        </div>
    <% end %>

I have a model where I am storing stuff. When the value of a boolean attribute (action_type) is false, then PostgreSQL rolls back the INSERT query for some reason.

create_table :process_flows do |t|
      t.integer :campaign_id
      t.integer :position
      t.string :description
      t.string :typestr
      t.float :action_number
      t.boolean :action_type
      t.string :action_on_donation
      t.integer :created_by
      t.integer :updated_by
      t.timestamps
end

My View file looks like:

<%= form_for [@org, @campaign, @process_flow] do |f| %>
        <%= render "shared/errors", :target => @process_flow %>
        <div class="field">
            <%= f.label :description %><br />
            <%= f.text_field :description %>
        </div>
        <div class="field">
            <%= f.label :typestr, 'Type of organization' %><br /><br />
            <%= f.select :typestr, options_for_select([["Point of collection", "PC", :selected => true], ["Your Organization", "O"], ["Bank / Payment Gateway", "B"], ["Intermediary", "I"], ["Recipient Charity Project", "R"]]) %><br /><br />
        </div>
        <%= f.select :action_on_donation, options_for_select([["100% (Unchanged)", "U", :selected => true], ["Increase", "A"], ["Decrease", "S"]]) %>
        the donation 
        by
        <%= f.text_field :action_number, :style=>"width: 30px;", :value => '0' %>
        <%= f.select :action_type, options_for_select([["Percent", '1', :selected => true], ["Flat Amount", '0']]) %>
        <div>
            <%= f.submit 'Add', :class=>'button' %>
        </div>
    <% end %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-12-06 18:18:39

这可能发生在许多平台上。

最典型的原因是缺少 COMMIT。当连接关闭时,PostgreSQL 将回滚打开的事务。

另一种可能性是您有一个代码分支没有执行,即使您期望它执行。

在这些情况下,重要的是通过遍历代码来调试代码(这里没有足够的代码可以继续)并确定是否正在发送插入以及是否发出了提交。

This can happen on many platforms.

The most typical cause for this is a missing COMMIT. PostgreSQL will roll back open transactions when the connection is closed.

Another possibility is that you have a code branch which is not executing even though you expect it to be.

In these cases it is important to debug your code by walking through it (there is not enough code here to go on) and determine whether the insert is being sent at all and whether a commit is ever issued.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文