我想用這段代碼創建一個表。如何使自動增量列非自動增量?
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();
});
}
當我試着php artisan migrate
它顯示我這個錯誤。
[Illuminate\Database\QueryException]
的BookInfo
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(
BOOKIDint not null auto_increment primary key,
名稱varchar(255) not null,
出版商varchar(255) null,
Publishing_yearint null auto_increment primary key,
價格int null auto_increment primary key,
語言varchar(30) not null,
created_attimestamp default 0 not null,
的updated_attimestamp default 0 not null) default character set utf8 collate utf8_unicode_ci)
和
[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
看來laravel通吃整列,自動遞增。這裏發生了什麼事實,而且t會是解決方案嗎?