2015-02-02 12 views
63

Właśnie rozpoczął laravel i dostaję ten błąd: Unknown column 'updated_at' insert into gebruikers (naam, wachtwoord, updated_at, created_at) wiem to updated_at rzeczą jest z kolumny timestamp podczas migracji stolik, ale ja nie używam updated_at. Używałem go, kiedy postępowałem zgodnie z samouczkiem Laravel, ale teraz, gdy robię (lub próbuję) własne rzeczy, otrzymuję ten błąd, mimo że nie używam znaczników czasu. Nie mogę znaleźć miejsca, w którym jest używany. Jest to kod:laravel: Unknown column „updated_at”

Kontroler:

public function created() 
{ 
    if (! User::isValidRegister(Input::all())) 
    { 
     return Redirect::back()->withInput()->withErrors(User::$errors); 
    } 


     // Register the new user or whatever. 
     $user = new User; 
     $user->naam = Input::get('naam'); 
     $user->wachtwoord = Hash::make(Input::get('password')); 
     $user->save(); 

     return Redirect::to('/users'); 
} 

Routing:

Route::get('created', '[email protected]'); 

Model:

public static $rules_register = [ 
    'naam' => 'unique:gebruikers,naam' 
]; 

public static $errors; 
protected $table = 'gebruikers'; 

public static function isValidRegister($data) 
    { 
     $validation = Validator::make($data, static::$rules_register); 

     if ($validation->passes()) 
     { 
      return true; 
     } 
     static::$errors = $validation->messages(); 
     return false; 
    } 

muszę być zapominając coś ... Co ja Robię źle tutaj?

+0

sprawdź swoją tabelę, jeśli masz kolumnę ** updated_at **! –

+0

@MehdiMaghrooni Nie. – Loko

+0

I to jest problem, chcesz uzyskać dostęp do kolumny, która nawet nie istnieje. Musisz albo zmienić swój stół, aby dodać ten, albo po prostu go usunąć. – Yang

Odpowiedz

175

W modelu wpisz poniższy kod;

public $timestamps = false; 

To zadziała.

+1

Czy mógłbyś opisać trochę dlaczego to działa? –

9

Dla tych, którzy są przy użyciu laravel 5 lub powyżej muszą używać modyfikatora publicznych innych mądrych będzie to wyjątek

Access level to App\yourModelName::$timestamps must be 
public (as in class Illuminate\Database\Eloquent\Model) 

public $timestamps = false; 
-3
$id = put her id; 
$update['user_id'] = $userId; 
Use where(array('_id'=>$id))->pull($update); 
0

Nicea Odpowiedź przez Alex i Sameer, ale może po prostu dodatkowych informacji na temat, dlaczego jest to konieczne umieścić

public $timestamps = false; 

znaczniki czasu są ładnie opisane na oficjalnej Laravel page:

By default, Eloquent expects created_at and updated_at columns to exist on your >tables. If you do not wish to have these columns automatically managed by >Eloquent, set the $timestamps property on your model to false.