我创建了这个迁移脚本,但它给出了以下错误。如果我将另一列的数据类型更改为字符串或其他类型,它不会给出任何错误。如何解决这个问题?
Schema::create('incidents', function (Blueprint $table) {
$table->string('id');
$table->primary('id');
$table->unsignedInteger('user_id', 255);
});
字符串
SQL [42000]:返回错误或访问冲突:1068定义了多个主键(SQL:alter table incidents
add primary key incidents_id_primary
(id
))
SQLSTATE[42000]:返回错误或访问冲突:1068定义了多个主键
编辑
由于没有任何工作,我将此user_id创建移动到另一个迁移脚本。现在它仍然无法运行第二个迁移脚本。给出此错误:
1068定义了多个主键(SQL:alter table incidents
add user_id
int unsigned not null auto_increment primary key)
看起来,如果主键不是整数,那么Laravel试图使下一个第一个整数列成为主列!
所以我的第一个剧本是,
public function up()
{
Schema::create('incidents', function (Blueprint $table) {
$table->string('id')->primary();
});
}
型
第二个剧本是,
public function up()
{
Schema::table('incidents', function($table) {
$table->unsignedInteger('user_id', 255);
});
}
型
1条答案
按热度按时间des4xlb01#
已关闭
就像这样:
字符串
别忘了加上你的模型
型
问题
根据laravel docs
型
您使用的函数接收bool作为参数,数字255被解释为true。