laravel中“字段列表”中的未知列'uuid'

问题描述 投票:0回答:1

我正在尝试在我的[[“ users”]]表中创建一个用UUID填充的列“ unique”,我不希望它是主要的,并且在我尝试注册用户时遇到此错误““字段列表”中的未知列“ uuid””我创建了一个新的laravel项目,并在其上使用了“ Auth”命令如果您还有其他方法可以执行此操作,请共享我只希望为用户提供5到8个唯一的字符代码

这里是我的用户迁移:-

public function up() { Schema::create('users', function (Blueprint $table) { $table->id(); $table->uuid('unique'); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); }

这里是我的用户模型:-

<?php namespace App; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Webpatser\Uuid\Uuid; use App\Models\Concerns\UsesUuid; use Illuminate\Support\Str; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $guarded = []; // YOLO public $incrementing = false; protected $keyType = 'string'; protected static function boot() { parent::boot(); self::creating(function ($user) { $user->uuid = (string) Uuid::generate(4); }); } protected $fillable = [ 'name', 'email', 'password', 'uuid', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; }

这是我的数据库的图片:-

enter image description here
这是我第一次使用UUID,所以我按照教程进行了操作因为我是laravel以及编程的初学者,所以我不知道问题是什么请帮助

-ThankYou

我正在尝试在我的“用户”表中创建一个用UUID填充的“唯一”列,我不希望它是主要的,并且当我尝试注册用户时,我遇到此错误“'中的未知列'uuid'字段列表'“ ...
php laravel uuid
1个回答
1
投票
您的迁移脚本创建的是列unique而不是uuid,这就是得到column uuid not not found的原因。 (请查看您的phpmyadmin屏幕截图第二列)
© www.soinside.com 2019 - 2024. All rights reserved.