Php 如何使自增列成为非自增列?
我正试图用这段代码创建一个表Php 如何使自增列成为非自增列?,php,mysql,laravel-5,Php,Mysql,Laravel 5,我正试图用这段代码创建一个表 public function up() { Schema::create('BookInfo', function (Blueprint $table) { $table->increments('id'); $table->integer('bookId',11); $table->string('Name',255); $table->string('Publish
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
时,它显示了这个错误
[Lightning\Database\QueryException]
SQLSTATE[42000]:语法错误或访问冲突:1075不正确
表格定义;只能有一个自动列,并且必须
被定义为键(SQL:create table
BookInfo(
bookIdint非
自动递增主键为空,
Namevarchar(255)不为空,
Publishervarchar(255)null,
Publishing\u yearint null
自动增量主键,
Priceint null自动增量主键,
Languagevarchar(30)非空,
在时间戳默认值0处创建
非空,
在时间戳默认值0非空)处更新\u默认字符
设置utf8 collate utf8\u unicode\u ci)
和
[PDO异常]
SQLSTATE[42000]:语法错误或访问冲突:1075不正确
表格定义;只能有一个自动列,并且必须为
定义为键
似乎laravel将所有整数列都视为自动增量。这里到底发生了什么,解决方案是什么?错误说明了一切
$table->integer('bookId',11);
^// this is considered as autoincrement rather than length
整数没有长度选项
看
参考文献如此,错误说明了一切
$table->integer('bookId',11);
^// this is considered as autoincrement rather than length
整数没有长度选项
看
参考SO和$table->integer('bookId',11)代码>在雄辩的ORM中语法不正确(您不能为整数设置任何大小限制),这会导致您的案例中出现错误
和$table->increments('id')代码>自动将id
设置为主键
在这里找到雄辩的ORM中所有必要的表格生成命令:$table->integer('bookId',11)代码>在雄辩的ORM中语法不正确(您不能为整数设置任何大小限制),这会导致您的案例中出现错误
和$table->increments('id')代码>自动将id
设置为主键
在雄辩的ORM中找到所有必要的表格构建命令: