所以我想,php artisan migrate:fresh但我收到這個錯誤
基表或視圖已存在:1050 表“角色”已存在
即使我從 phpmyadmin 洗掉資料庫,清理快取并再次創建資料庫它仍然顯示相同的訊息表行的遷移如下:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('status');
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}
顯示的完整錯誤:
SQLSTATE[42S01]:基表或視圖已經存在:1050 表“角色”已經存在(SQL:創建表
roles(idbigint unsigned not null auto_increment 主鍵,namevarchar(255) not null,guard_namevarchar(255) not null,created_attimestamp null,updated_at時間戳 null) 默認字符集 utf8mb4 collat??e 'utf8mb4_unicode_ci')
這是為什么?我可以或應該做什么?
uj5u.com熱心網友回復:
首先使用此代碼洗掉角色表,Schema::dropIfExists('roles');然后創建。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::dropIfExists('roles'); //added
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('status');
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}
uj5u.com熱心網友回復:
如果它在您進行 artisan migrate 之前已經存在,它當然會說這個。你有沒有遷移,它中途壞了?您可以重置它或只是洗掉表并重試(如果您在本地開發中并且可以洗掉它)。
php工匠遷移:重置
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/356360.html
上一篇:SQL中的直接關系
下一篇:如何復制過去5分鐘內更新過的表?
