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
.create는 테이블에 자동 증가가 수행되면 ID를 할당합니다. – Nithin