簡體   English   中英

Laravel MySQL錯誤1054

[英]Laravel MySQL Error 1054

我有一個煩人的小問題,試圖在Laravel的一個分頁網格中刪除一行,幾天前運行良好,現在,每當我嘗試刪除任何記錄時,我在所有網格中都遇到這個問題。 這是錯誤的示例:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.id' 
 in 'where clause' (SQL: delete from `users` where `id` = 9) 

現在我的實際代碼:

向上遷移

Schema::create('users', function(Blueprint $table){
    $table->increments('id');
    $table->string('username', 50);
    $table->string('password', 50);
    $table->string('email', 50);
    $table->tinyInteger('roles_id');
    $table->string('remember_token', 255);
    $table->timestamps();
});

視圖

{{ Form::open(array('action' => array('UserController@delete_user'), 'method' => 'delete')) }}
{{ Form::submit('Delete', array('class'=>'btn btn-danger', 'title'=>'Delete', 'style'=>'width:70px;height:35px;margin-left:100px;')) }}
{{ Form::hidden('id','',array('id'=>'identifier')) }}
{{ Form::close() }}

路線

Route::delete('users/delete', array('uses'=>'UserController@delete_user'))->before('auth');

控制器用戶控制器

public function delete_destroy(){
    $id = Input::get('id');
    User::findOrFail($id)->delete();
    return Redirect::route('users');
}

模型使用者

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $table = 'users';

    protected $hidden = array('password');

    protected $fillable = array('username', 'email', 'password', 'roles_id');
    public static $accessible = array('username', 'email', 'roles_id');

    private static function rules(){
        return array(
                    'username' => 'required|min:6|max:20|unique:users,username,"'.Input::get('id').'"',
                    'password' => 'required|min:8',
                    'email'    => 'required|email',
                    'roles_id' => 'required|numeric|min:1',
                    );
    }
//Bunch of other native functions
}

這幾乎就是我所有的路線,視圖,模型和控制器的外觀。

我只是在刪除記錄方面遇到麻煩,創建和更新工作正常。 直到幾天前我最后一次刪除記錄時,“刪除”工作正常。 今天,我在視圖中嘗試了不同的操作,從創建到更新,然后當我嘗試將其刪除時,出現了先前引用的錯誤消息。

我找出了錯誤的原因。 原來我有4個表的觸發器,像這樣。 以下示例僅適用於users表:

CREATE TRIGGER `delete_privileges` AFTER DELETE ON `users` FOR EACH ROW
BEGIN
DELETE FROM users_controllers_actions 
       WHERE users_controllers_actions.users_id=users.id;
END;

猜猜這不是正確的語法...也許是DELETED.id或OLD.id ...我不習慣在MySQL中使用觸發器,但在SQL Server中使用觸發器。

我沒有通過使用外鍵約束來做我應該做的事情……我最初沒有設置它是因為它給了我語法錯誤。 但是,如果有人能告訴我正確的語法來創建類似於我顯然試圖創建的觸發器的觸發器,我將不勝感激。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM