SQLSTATE[42S21]:列已存在:1060 重复的列名"id"



尝试迁移后出现错误。我没有对其他页面做任何修改。

每个表都被创建为migrate默认值,但是没有创建我的articles表。

这是我在CMD中得到的错误:SQLSTATE[42S21]: Column already exists: 1060

这是我的_create_articles_table。php页面

<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
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 AppProviders;
use IlluminateSupportServiceProvider;
use Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{

}
}

感谢您的宝贵时间。

显然,您定义了两次id列,不需要添加这一行:

$table->increments('id');

这将使其默认为自动递增:

$table->id();

CMD: SQLSTATE[42S21]: Column already exists: 1060重复列名'id '

这意味着您的id字段在迁移查询中定义了两次,因此请删除文章中的这一行.

$table->increments('id');

在运行时迁移你的表

最新更新