在Laravel中运行迁移后无法创建新表

时间:2019-05-11 11:28:07

标签: php laravel laravel-5

我是Laravel新手,我为Admin创建了一个新模型并为admin添加了迁移文件,但是当我运行migration命令时,它不会为Admin生成表,而是生成剩余的迁移,即正在生成用户和密码重置。我已经尝试过php artisan migrate:refresh命令,但是没有用。运行php artisan migrate:status显示所有表。请帮助解决我的问题。

我的代码是:

  

2019_05_11_083510_create_admins_table.php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminsTable extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up() {
        Schema::create('admins', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

型号:Admin.php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Admin extends Authenticatable
{
    use Notifiable;
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

1 个答案:

答案 0 :(得分:0)

听起来您的迁移表中已经有一个条目,并且由于某种原因'migrate:fresh'无法正常工作,或者您无意间尝试了'migrate:refresh'。

想法

所以我想尝试的第一件事:

  • 您说过'php artisan migration:refresh'尝试做'php artisan migration:fresh'。
  • 如果migrate:fresh不起作用,请进入您的SQL并编辑迁移表,并删除要运行的迁移条目,然后运行“ php artisan migration”。
  • 如果上述任何一项都没有,您可以尝试进行“ php artisan优化”,这将清除所有内容的所有缓存,并使您遍历发现的错误。

希望这回答了您的问题,祝您好运!

相关问题