2015-01-31 1 views
0

My ReportNu 모델이 고유 ID 컬럼이 "oid"인 기존 테이블에 연결되어 있습니다..new가 새 오브젝트에 id를 할당하지 않습니다.

ERROR: null value in column "oid" violates not-null constraint DETAIL: Failing row contains (null, 2, 2, 106341051, 2016, 0, 0, null, null). 

자동에 1 증가, 나를 위해 OID를 설정하는 레일을 말할 수있는 방법이 있어야합니다 같은 느낌 : 나는 새 보고서를 만들려고 할 때, 나는 다음과 같은 오류가 발생합니다. 어떻게해야합니까? 레일 콘솔을로드하고 ReportNu.new는 oid가 0 인 인스턴스를 만듭니다.

다음은 내 파일의 관련 부분입니다.

report_nu.rb :

class ReportNu < ActiveRecord::Base 
    self.table_name = "t_report_cust" 
    self.primary_key = "oid" 
    ... 
end 

new.html.erb

def new 
    @report_nu = ReportNu.new 
    end 

    def create 
    @report_nu = ReportNu.new(report_nu_params) 

    respond_to do |format| 
     if @report_nu.save 
     format.html { redirect_to @report_nu, notice: 'Report nu was successfully created.' } 
     format.json { render :show, status: :created, location: @report_nu } 
     else 
     format.html { render :new } 
     format.json { render json: @report_nu.errors, status: :unprocessable_entity } 
     end 
    end 
    end 
+1

.create는 테이블에 자동 증가가 수행되면 ID를 할당합니다. – Nithin

답변

0

@Nithin 위에서 자신의 의견에 나를 위해이 대답

<%= form_for(@report_nu) do |f| %> 
    <%= f.hidden_field :cust_id, :value => current_user.id %><br> 
    <div class="field"> 
    <%= f.label :spec_id %><br> 
    <%= f.text_field :spec_id %> 
    </div> 
    <div class="field"> 
    <%= f.label :hid %><br> 
    <%= f.text_field :hid %> 
    </div> 
    <div class="field"> 
    <%= f.label :fore_yr %><br> 
    <%= f.text_field :fore_yr %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

reports_controller.rb. 내가 작업하고 있던 테이블에는 기본 키가 자동 증가로 설정되어 있지 않습니다. 나는 테이블을 만들지 않았고 그것을 찾을 줄조차 모릅니다. 감사 Nithin! 답변으로 의견을 게시하면 확인하고 내 "응답"을 삭제합니다

관련 문제