gpt4 book ai didi

mysql - 为什么数据库中不存在该表

转载 作者:行者123 更新时间:2023-11-29 15:34:56 24 4
gpt4 key购买 nike

我的代码有什么问题?,迁移成功但表不存在

public function up()
{
Schema::create('student', function (Blueprint $table) {
$table->varchar('student_id', 6)->primary_key()->nullable(false);
$table->varchar('student_name', 50)->nullable(false);
$table->enum('student_class', ['RPL-1','RPL-2','RPL-3'])->nullable(true);
$table->enum('student_gender', ['MALE','FEMALE'])->nullable(true);
$table->text('student_address')->nullable(true);
$table->tinyinteger('student_status', ['1'])->default('1');
$table->timestamps();
});
}

最佳答案

由于尝试使用 Laravel 中不可用的函数或误用函数,示例中的迁移将不会运行。我已经将新的迁移放在一起并进行了测试,它运行良好。

Schema::create('student', function (Blueprint $table) {
$table->string('student_id', 6)->primary_key()->nullable(false);
$table->string('student_name', 50)->nullable(false);
$table->enum('student_class', ['RPL-1', 'RPL-2', 'RPL-3'])->nullable(true);
$table->enum('student_gender', ['MALE', 'FEMALE'])->nullable(true);
$table->text('student_address')->nullable(true);
$table->tinyinteger('student_status')->default('1');
$table->timestamps();
});

我假设 student_id 需要是应用程序中的某种唯一代码,因此我将其更改为使用 string 函数。这将创建一个 varchar 类型字段,第二个参数是字符串的长度。

我还更改了 student_statustinyinteger 函数参数,看起来您正在尝试指定所有可能的值,类似于您使用 枚举。 tinyinteger 类型不能接受可能值的列表,因此您可能需要将其更改为 bool 值(如果状态为 true 或 false)、枚举或相关表的外键(如果相关) .

如果您在应用程序中使用 Eloquent ORM,则可能不需要为所有列名称添加 student 前缀。如果使用正确,您应该能够简单地使用所存储的变量的名称,例如 student_name 将变为 name

关于mysql - 为什么数据库中不存在该表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58342642/

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