mardi 8 mars 2016

Laravel 5.2 [PDOException] SQLSTATE[42000] - creates two auto_increment primary keys fields

Good day, I have two migration tables, the first one is for creating a customers schema:

Schema::create('customers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name',45);
        $table->string('middle_name',45)->nullable();
        $table->string('last_name',45);
        $table->string('gender',45);
        $table->string('dob',45);
        $table->string('martial_status',45);
        $table->string('home_phone',12)->nullable();
        $table->string('mobile_phone',12);
        $table->string('work_phone',12);
        $table->string('id_number',12);
        $table->string('id_type',45);
        $table->string('id_exp',20);
        $table->date('id_issue_date');
        $table->text('id_image')->nullable();
        $table->timestamps();

The second one is for creating a customer_address schema:

   Schema::create('customers_address', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('customer_id')->unsigned();
        $table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
        $table->string('address_line1',20);
        $table->string('address_line2',20)->nullable();
        $table->string('ownership',20);
        $table->string('country');
        $table->string('town_city');
        $table->string('parish_state');
        $table->integer('years_at_address',10);
        $table->timestamps();
    });

when running php artisan migrate, I get an error in my terminal saying [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key.

What could the cause of me getting this, because I do not see what I am doing wrong here. Thanks in advance for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire