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

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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号