首页 > 解决方案 > 拉拉维尔 | 当我运行 php artisan migrate 命令时出现 MySQL 错误

问题描述

我要安装Concierge - Laravel 5.x

在简单的汽车租赁预订中使用它并进行手动验证和确认

安装后,添加提供者和发布供应商

迁移数据库时出现此错误:

Illuminate\Database\QueryException : SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册 f 或在 'after iddeleted_attimestamp null、 created_attimestamp null、updated_a' at line 1 (SQL: create table services (id int unsigned not null auto_increment p rimary key, business_id int unsigned not null,slug varchar(255) not null, namevarchar(255) not null,持续时间int unsigned not null default '60',描述附近使用的正确语法varchar(255) not null,prere quisites varchar(255) null,color varchar(12) null,type_id int unsigned null afterid ,deleted_at timestamp null,created_at timestamp null,updated_at` timestamp null) 默认字符集 utf8mb4整理'utf8mb4_unicode_ci')

迁移:

Schema::create('services', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('business_id')->unsigned();
            $table->foreign('business_id')->references('id')->on('businesses')->onDelete('cascade');
            $table->string('slug');
            $table->string('name');
            $table->integer('duration')->unsigned()->default(60);
            $table->string('description');
            $table->string('prerequisites')->nullable();
            $table->string('color', 12)->nullable();
            $table->integer('type_id')->unsigned()->nullable()->after('id');
            $table->foreign('type_id')->references('id')->on('service_types')->onDelete('cascade');
            $table->softDeletes();
            $table->Timestamps();

            $table->unique(['business_id', 'slug']);
        });

标签: phpmysqllaravel

解决方案


您调用的方法出现问题

after方法用于列修饰符

示例:当您需要修改表服务时,它将像这样工作。但如果您创建表格,则没有必要。您可以在将属性写入迁移文件时对其进行序列化。

Schema::table('services', function (Blueprint $table) {
     $table->integer('type_id')->unsigned()->nullable()->after('id');
});

所以在你的代码中它应该是这样的:

Schema::create('services', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('type_id')->unsigned()->nullable();
            $table->integer('business_id')->unsigned();
            $table->foreign('business_id')->references('id')->on('businesses')->onDelete('cascade');
            $table->string('slug');
            $table->string('name');
            $table->integer('duration')->unsigned()->default(60);
            $table->string('description');
            $table->string('prerequisites')->nullable();
            $table->string('color', 12)->nullable();
            $table->foreign('type_id')->references('id')->on('service_types')->onDelete('cascade');
            $table->softDeletes();
            $table->Timestamps();

            $table->unique(['business_id', 'slug']);
        });

推荐阅读