首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么数据库中不存在该表

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

Stack Overflow用户
提问于 2019-10-11 21:47:36
回答 1查看 48关注 0票数 0

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

代码语言:javascript
复制
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();
    });
}
EN

回答 1

Stack Overflow用户

发布于 2019-10-12 01:48:52

由于尝试使用Laravel中不可用的函数或对函数的误用,示例中的迁移将不会运行。我已经组装了一个新的迁移,并对其进行了测试,它运行得很好。

代码语言:javascript
复制
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函数参数,看起来您正在尝试指定所有可能的值,类似于您使用的enumtinyinteger类型不能接受可能值的列表,因此您可能希望将其更改为布尔值(如果状态为true或false)、枚举或相关表的外键(如果相关)。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58342642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档