繁体   English   中英

在Laravel中创建用户表

[英]Creating users table in Laravel

我在laravel的用户表上遇到了一些麻烦。 我很久以前就删除了那些默认表。 现在我正在尝试使用Auth,但我无法注册。 因为数据库中没有表。 但我也无法用php artisan migrate.创建表php artisan migrate. 因为我已经删除了那些迁移表。 所以我想再次创建这些表。 但我找不到默认文件。

并且make:auth不带表...我需要自己重新创建它。 我记得有两个不同的表然后一个是用户和重置密码? 有谁知道我在哪里可以再次获得thoese牌桌?

只需运行这些命令

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

在您的迁移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();
        });
    }

在您的迁移中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();
        });
    }

在那之后

php artisan migrate:refresh

PS:这将重置您的数据库或只是运行

php artisan migrate

编辑:如果面临错误1071 Specified key was too long; max key length is 767 bytes 1071 Specified key was too long; max key length is 767 bytes

在你的AppServiceProvider.php添加这个

use Illuminate\Support\Facades\Schema; //this

public function boot()
{
    Schema::defaultStringLength(191); //this
}

您可以从laravel存储库中检索已删除的迁移: https//github.com/laravel/laravel/tree/master/database/migrations

2014_10_12_000000_create_users_table.php:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    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();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

2014_10_12_100000_create_password_resets_table.php:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('password_resets');
    }
}

你应该运行以下命令:

php artisan make:auth

然后在命令下运行

php artisan migrate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM