【发布时间】:2021-09-12 13:59:41
【问题描述】:
尝试迁移后出现错误。 并且我没有对其他页面进行任何更改。
作为迁移默认创建的每个表,但它没有创建我的文章表。
这是我在 CMD 中遇到的错误: SQLSTATE[42S21]: 列已经存在: 1060 Duplicate column name 'id'
这是我的 _create_articles_table.php 页面:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->id();
$table->increments('id');
$table->timestamps();
$table->string('title');
$table->text('body');
$table->boolean('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}
这是我的 AppServiceProvider 页面:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
}
}
感谢您的宝贵时间。
【问题讨论】:
-
执行
$table->id();等同于$table->increments('id');,因此无需执行两次。删除其中一个