sqlstates42000语法错误或访问冲突:1075

时间:2017-11-21 02:46:42

标签: sql laravel-5.5

SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;只有一个汽车colu   mn并且必须将其定义为键(SQL:create table COLUMN | ------- Pizza Burger Broccoli tbl_category int not null,cat_id varchar(50)    not null,cat_name varchar(100)not null,cat_detail varchar(50)not null,cat_img int not null auto_incremen   t主键,menu_id int not null auto_increment主键,parent_id时间戳不为空,cat_update t   imestamp null,created_at timestamp null)默认字符集utf8 collat​​e utf8_unicode_ci)

updated_at

帮帮我

2 个答案:

答案 0 :(得分:1)

问题在于您尝试在两列(menu_id和parent_id)中创建具有自动增量和主键属性的表:

menu_id int not null auto_increment primary key, parent_id int not null auto_increment primary key

你必须只选择一列,我猜(按表名),它应该是cat_id。

this docs开始,我猜您可以将cat_id的定义更改为:

$table->integer('cat_id')->autoIncrement()...

$table->increments('cat_id')...

答案 1 :(得分:0)

我的代码:

<?php

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

class CreateTblCategoryTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tbl_category', function (Blueprint $table) {
            $table->integer('cat_id')->PRIMARYKEY->NOTNULL;
            $table->string('cat_name',50);
            $table->string('cat_detail', 100);
            $table->string('cat_img', 50);
            $table->integer('menu_id', 11)->NOTNULL;
            $table->integer('parent_id', 11)->NOTNULL;
            $table->timestamp('cat_update')->NOTNULL;
             $table->timestamps();
        });
    }

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