mysql - 为什么表在数据库中不存在
问题描述
我的代码有什么问题?,迁移成功但表不存在
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 类型字段,第二个参数是字符串的长度。
我还更改了 的tinyinteger
函数参数student_status
,看起来您正在尝试指定所有可能的值,类似于您对enum
. 该tinyinteger
类型不能采用可能值的列表,因此您可能希望将其更改为布尔值(如果状态为真或假)、枚举或相关表的外键(如果相关)。
如果您在应用程序中使用 Eloquent ORM,则可能不需要在所有列名前加上student
. 如果使用正确,您应该能够简单地使用所存储变量的名称,例如student_name
将成为name
.
推荐阅读
- django - Django,使用表单集上传多个图像
- node.js - 微服务,任务完成时如何通知后端
- kubernetes - Pod 生命周期和 liveness 有什么区别?
- java - 未解决的依赖关系:maven 中的 io.swagger:swagger-core:jar
- deep-learning - torch.nn.conv2d 和 torch.nn.Linear 中的值
- java - Handler is Unreachable 语句
- dialogflow-es - 如何使用 googleflow 平台在电报下嵌入视频作为响应?
- php - Laravel 谷歌云应用引擎会话问题
- python - 如何创建指向列表的指针,以便通过指针访问提供不可变元素?
- python - Scipy.spatial 不包含“qhull”