gpt4 book ai didi

php - 当我尝试使用 laravel 添加主键的数据类型字符串时发生错误

转载 作者:行者123 更新时间:2023-11-29 05:12:39 25 4
gpt4 key购买 nike

代码在这里

public function up()
{
Schema::create('semesters', function (Blueprint $table) {
// $table->increments('id');
$table->engine = 'InnoDB';

$table->string('semester_id')->unique()->unsigned();

$table->timestamps();

});
}

错误在这里

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'unsigned not null, created_at times tamp default 0 not null, updated_at times' at line 1 (SQL: create table semesters (semester_id text unsigned not null, created_at timestamp default 0 not null, updated_at timestamp default 0 not null) default character s et utf8 collate utf8_unicode_ci engine = InnoDB)

最佳答案

混合类型:stringunsigned(即 int)

因此,如果您需要此列为字符串,您应该在此处去掉unsigned part:

 $table->string('semester_id')->unique()->unsigned(); <---

所以那一行变成:

 $table->string('semester_id')->unique(); 

关于php - 当我尝试使用 laravel 添加主键的数据类型字符串时发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37255828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com