9

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?

2
  • 1
    I suppose you can use the default ones found in the public git to replace the ones you've deleted. While it may not solve your problem completely, it's a good starting point. Commented Nov 12, 2018 at 7:14
  • Do you need to create default users table? Commented Nov 12, 2018 at 7:14

3 Answers 3

24

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
}
Sign up to request clarification or add additional context in comments.

10 Comments

Thank you mate, this is what I want! I check your answer!
but it's giving me this error: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email)) when I try to migrate
edit your AppServiceProvider.php use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
Edited answer please check
File is located at {ProjectLocation}/app/Providers/AppServiceProvider.php
|
5

You can retrieve those deleted migrations from laravel repository : 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');
    }
}

3 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Please add some explanation to that code such that others can learn from it
@NicoHaase I think this is clear for one who know laravel, but if I can, sure I will add some explanation.
0

You should run below command:

php artisan make:auth

then run below command

php artisan migrate

4 Comments

did you read the question? make auth doesn't bring the users and reset password table
@Snickers: Please check migration folder you have any users migration file
no there isn't. because I delete those long time ago. and make:auth doesn't bring those.
@Snickers You need to install new fresh version of the laravel and copy the user migration file from new version and past in your current version then you can perform the above command , it will works...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.