【发布时间】:2021-12-06 09:53:45
【问题描述】:
我正在尝试将我的应用程序切换为使用 Uuid,但我的迁移在事件表上失败。
SQLSTATE[42000]:语法错误或访问冲突:1068 定义了多个主键(SQL:alter table
eventsadd primary keyevents_id_primary(id))
Schema::create('events', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('title', 255);
$table->integer('join_id', 6)->unique();
$table->string('image')->nullable();
$table->string('location')->nullable();
$table->text('description')->nullable();
$table->timestamp('event_date')->nullable();
$table->timestamp('event_time')->nullable();
$table->foreignUuid('user_id')->nullable()->index();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->softDeletes();
$table->timestamps();
});
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name')->nullable();
$table->string('email')->unique();
$table->string('username')->nullable();
$table->string('avatar')->nullable();
$table->string('phone_number')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
非常感谢任何帮助!
【问题讨论】:
标签: php laravel laravel-8 database-migration