2015-01-27 15 views
0

최근 프로젝트에서 사용자 테이블 (사용자 테이블이 id 대신 user_id이라고 불렀음) 중 하나에 대한 사용자 지정 ID 이름이 있습니다.Laravel의 ID 명명 규칙

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update users set active = 1, code = , updated_at = 2015-01-20 21:28:14 where id is null) 

내가 Laravel의 선호도를 양복지 따라서, id 내 테이블의 id 컬럼 이름을 변경하여 그것을 해결 : 나는 그것을에 데이터를 삽입하려고 할 때

, 나는 다음과 같은 오류가 발생했습니다.

그러나 Laravel을 사용하는 동안 특정 테이블에서 사용자 지정 ID 이름을 사용해야하는 경우이 문제에 대한 최상의 솔루션/해결 방법은 무엇입니까? 워드 프로세서

답변

3

는 :

http://laravel.com/docs/4.2/eloquent

Note: Eloquent will also assume that each table has a primary key column named id. You may define a primaryKey property to override this convention. Likewise, you may define a connection property to override the name of the database connection that should be used when utilizing the model.

그래서, 모델에, 당신은 단지 추가합니다 :

protected $primaryKey = 'user_id';