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条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R