dtvdz911959
2018-05-18 15:38
浏览 233
已采纳

laravel“SQLSTATE [HY000]:一般错误:1没有这样的表:user”但是'users'表存在

I am running Laravel 5.2, on Windows 8.1 using XAMPP with php 7.2, and I am trying to register a user using laravel auth register form with sqlite database. However when I try insert new record to table users I got error.

SQLSTATE[HY000]: General error: 1 no such table: user

When I migrate database it creates users table. But when I try to insert new record in users table with register form it tries to access user table. So I created user table in database it works fine but the record is inserted in users table and not in user table.

Migration

public function up(){
    Schema::create('users', function (Blueprint $table) {
        $table->increments('user_id');
        $table->string('name');
        $table->string('role');
        $table->string('username');
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
        });
    }

public function down(){
    Schema::drop('users');
}

User model

class User extends Authenticatable{
    protected $primaryKey = 'user_id';

    protected $fillable = [
        'name', 'role', 'username', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];
}

AuthController

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller{

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    protected $redirectTo = '/';
    protected $username = 'username';

    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'role' => 'required|max:7',
            'username' => 'required|unique:user',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'role' => $data['role'],
            'username' =>$data['username'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

thanks for help and sorry for bad english.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题