我的代码出了什么问题?迁移成功但表不存在
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();
});
}发布于 2019-10-12 01:48:52
由于尝试使用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_status的tinyinteger函数参数,看起来您正在尝试指定所有可能的值,类似于您使用的enum。tinyinteger类型不能接受可能值的列表,因此您可能希望将其更改为布尔值(如果状态为true或false)、枚举或相关表的外键(如果相关)。
如果您在应用程序中使用Eloquent ORM,则可能不需要在所有列名前都加上student前缀。如果使用正确,您应该能够简单地使用正在存储的变量的名称,例如,student_name将变为name。
https://stackoverflow.com/questions/58342642
复制相似问题