即使在进行php artisan迁移之后,Password_resets表仍然丢失

时间:2019-06-03 18:21:41

标签: laravel postgresql

我正在尝试在laravel中进行密码恢复,但是在插入一封电子邮件以发送重置请求后,出现一个错误,提示password_resets不存在。

我已经尝试过再次迁移,但没有任何效果。

SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "password_resets" does not exist 
LINE 1: delete from "password_resets" where "email" = $1 ^ (SQL: delete from "password_resets" where "email" = blabla@gmail.com)

2 个答案:

答案 0 :(得分:0)

根据this,似乎不再存在为password_resets生成迁移的命令,您可以尝试使用以下命令创建新的迁移:

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')->index();
            $table->timestamp('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('password_resets');
    }
}
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')->index();
            $table->timestamp('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('password_resets');
    }
}

答案 1 :(得分:0)

就我而言,我通过在 AppServiceProvider.php 中添加这两行来解决缺少表格的问题。

请按照以下步骤操作:-

  1. 打开AppServiceProvider.php(位置:app/Providers/AppServiceProvider.php)。
  2. 在类 use Illuminate\Support\Facades\Schema; 之外添加此行
  3. function boot() Schema::defaultStringLength(191);
  4. 中添加这一行
  5. 删除数据库中的所有表。
  6. 运行这个命令php artisan migrate

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
}