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 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?