2017-02-14 1 views
1

관계와 함께이 오류 메시지가 표시되지만이 오류를 중지하기 위해 수행해야 할 작업을 찾을 수 없습니다 ..OcotberCMS - "SQLSTATE [42S22] : 열을 찾을 수 없음 : 1054 알 수없는 열 'users.application_id'

나는 컨트롤러와 구성 요소를 사용하여 응용 프로그램 모델을 가지고있다. 백엔드에서 나는 새로운 응용 프로그램 레코드를 추가 할 수 있습니다.하지만이 오류가 볼 수 있습니다.

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id' in 'where clause' (SQL: select * from `users` where `users`.`deleted_at` is null and `users`.`application_id` = 1 and `users`.`application_id` is not null limit 1)" on line 662 of /srv/users/sssandwich/apps/website/public/vendor/laravel/framework/src/Illuminate/Database/Connection.php 

나는이 코드를 추가 할 때 나타나는 오류를 격리 필드에서 .yaml은 Acme \ Models \ Application \ fields.yaml.

Acme\Models\Application.php 

에서

나는

public function up() 
{ 
    Schema::create('acme_acme_applications', function(Blueprint $table) { 
     $table->engine = 'InnoDB'; 
     $table->increments('id'); 
     $table->string('jobs_id')->nullable()->index(); 
     $table->string('application_id')->nullable()->index(); 
     $table->string('owner_id')->nullable()->index(); 
     $table->string('user_id')->nullable()->index(); 
     $table->string('vacancy_id')->nullable()->index(); 
     $table->string('ref_no', 50)->nullable(); 
     $table->char('status_update')->nullable(); 
     $table->timestamps(); 
    }); 
} 

내가 grep'd 한 'APPLICATION_ID'와 ...

/** 
    * @var array Relations 
    */ 
    public $hasOne = [ 
    'client' => ['RainLab\User\Models\User', 'table' => 'users'], 
    'cv' => ['Acme\Acme\Models\Cv'] 
    ]; 
    public $hasMany = []; 
    public $belongsTo = [ 
    'owner' => ['Backend\Models\User'] 
    ]; 
다음

데이터베이스 구조이기 때문에 설정 한 관계를 가지고 db 구조에서만 나타납니다. users 테이블은 Rainlab User 플러그인이지만 왜 그 테이블에서 application_id를 찾으려고하는지 확신 할 수 없습니다.

+0

응용 프로그램에서 hasOne 클라이언트 관계를 제거하면 너무 많이 드릴 다운하는 것처럼 보입니다. 그렇지 않으면 대신 키를 추가하십시오. – aynber

+0

감사합니다.하지만 hasOne 클라이언트를 제거하면 응용 프로그램을 제출 한 사용자의 이름이 표시되지 않습니다. 하지만 왜 아직도 application_id를 찾지 못했습니다. – ServerSideSkittles

+0

응용 프로그램의 클라이언트를 가져 오는 중일 수 있습니다. 클라이언트에 키를 추가하십시오 (외부 키는 id, 로컬 키는 user_id). 형식을 인식하지 못하기 때문에 추가 할 방법을 모르겠습니다. – aynber

답변

3
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id'... 

이 오류가 단정 응용 프로그램 모델은 당신이 일대일 관계를 정의하기 때문에 application_id 외래 키를 가지고 있다고 가정한다 생각; 응용 프로그램은 사용자 하나가있는 경우

다음 사용자의 테이블은 application_id 열이 포함되어야합니다

public $hasOne = [ 
    'client' => [ 
    'RainLab\User\Models\User', 
    'table' => 'users', 
    'key' => 'application_id', // the foreign key in User's table 
    'otherKey' => 'id', // Model record id 
     ], 
    ]; 

그리고 당신은 사용자 모델의 역의 관계, 사용자 belongsTo

public $belongsTo = [ 
    'application' => [ 
    'Acme\Models\Application', 
    'table' => 'acme_acme_applications', 
    'key' => 'application_id', 
    'otherKey' => 'id', 
     ], 
    ]; 

을 정의해야합니다 RainLab 사용자의 플러그인을 직접 편집하고 싶지 않다면 (업데이트 중에 변경 사항이 손실 될 것입니다) here 플러그인을 확장하고 데이터베이스에 여러 열을 추가하는 방법을 살펴보십시오.

관련 문제