Laravel 8 迁移显示“SQLSTATE[42000]:语法错误或访问冲突:1064 你的 SQL 语法有错误”

运行“php artisan migrate:fresh”命令时,它显示 SQLSTATE[42000] 错误

这是完整的错误消息

SQLSTATE[42000]:语法错误或访问冲突:1064 你的 SQL 语法有错误;检查手册对应到你的MySQL服务器版本正确的语法使用近“无符号不为空,created_at时间戳无效,updated_at时间戳空)DEF”位于第1行(SQL:CREATE TABLE productsidBIGINT的无符号NOT NULL的auto_increment主键,name为varchar(191 ) not null, descriptionvarchar(1000) not null, quantityint unsigned not null, statusvarchar(191) not null 默认'unavailable', imagevarchar(191) not null 默认'unavailable', seller_idvarchar(191) unsigned not null, created_attimestamp null, updated_attimestamp null) 默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

这是迁移 Product::UNAVAILABLE_PRODUCT 在 Product 模型中定义为“unavailabel”

public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('description',1000);
            $table->integer('quantity')->unsigned();
            $table->string('status',)->default(Product::UNAVAILABLE_PRODUCT);
            $table->string('image',)->default(Product::UNAVAILABLE_PRODUCT);
            $table->string('seller_id',)->unsigned();
            $table->timestamps();

            $table->foreign('seller_id')->references('id')->on('users');
        });
    }

回答

        $table->string('seller_id',)->unsigned();

没有无符号字符串这样的东西。删除unsigned()此列的选项,或者将其定义为整数。


以上是Laravel 8 迁移显示“SQLSTATE[42000]:语法错误或访问冲突:1064 你的 SQL 语法有错误”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>