mercredi 2 décembre 2015

How can I make auto-increment columns non-auto-increment?

I am trying to create a table with this code.

public function up()
{
    Schema::create('BookInfo', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('bookId',11);
        $table->string('Name',255);
        $table->string('Publisher')->nullable();
        $table->integer('Publishing_year',4)->nullable();
        $table->integer('Price',5)->nullable();
        $table->string('Language',30);
        $table->timestamps();
    });
}

When I tried php artisan migrate it shows me this error.

[Illuminate\Database\QueryException]
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 (SQL: create table
BookInfo(bookIdint not null auto_increment primary key,Namevarchar(255) not null, Publishervarchar(255) null,Publishing_yearint null auto_increment primary key,Priceint null auto_increment primary key, Languagevarchar(30) not null,created_attimestamp default 0 not null,updated_attimestamp default 0 not null) default character set utf8 collate utf8_unicode_ci) and

[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

It seems laravel takes all the integer columns as auto-increment.What happened here actually and what will be solution?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire