为什么 PostgreSQL 会回滚我的 INSERT 语句?
我有一个用来存储东西的模型。当布尔属性 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能发生在许多平台上。
最典型的原因是缺少 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.