dongyinglan8707 2018-11-12 07:04
浏览 264
已采纳

在Laravel中创建用户表

I have some trouble with the laravel's users table. I already deleted those default table long time ago. And now I am trying to use Auth but I can't register. because there is no table in the database. But also i can't create table with php artisan migrate. because I already deleted those migration tables. So I want create those tables once more. But I couldn't find the default files.

And make:auth is doesn't bring the table... I need to recreate it by myself. I remember there two diffrent tables back then one is users and reset password? Do anyone know where can I get thoese tables again?

  • 写回答

3条回答 默认 最新

  • duandaodao6951 2018-11-12 07:15
    关注

    Just run these commands

    php artisan make:migration create_users_table
    php artisan make:migration create_password_resets_table
    

    In your migration create_users_table

    public function up()
        {
            Schema::create('users', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->string('email')->unique();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('password');
                $table->rememberToken();
                $table->timestamps();
            });
        }
    

    In your migration create_password_resets_table

     public function up()
        {
            Schema::create('password_resets', function (Blueprint $table) {
                $table->string('email')->index();
                $table->string('token');
                $table->timestamp('created_at')->nullable();
            });
        }
    

    after that run

    php artisan migrate:refresh
    

    PS: This will reset your database Or just run

    php artisan migrate
    

    EDIT: If facing error 1071 Specified key was too long; max key length is 767 bytes

    In your AppServiceProvider.php add this

    use Illuminate\Support\Facades\Schema; //this
    
    public function boot()
    {
        Schema::defaultStringLength(191); //this
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动