我正在嘗試將我的應用程式切換為使用 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();
});
任何幫助是極大的贊賞!
uj5u.com熱心網友回復:
當您檢查檔案時,integer()您會發現第二個引數不是用于大小,而是用于欄位的自動增量/主要引數。整數型別本身就是一個大小(tinyInteger, smallInteger, bigInteger, ...)。并且6變成布林值回傳true。
/**
* Create a new integer (4-byte) column on the table.
*
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function integer($column, $autoIncrement = false, $unsigned = false)
{
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
}
你只需要洗掉那 6
Schema::create('events', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('title', 255);
$table->integer('join_id')->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();
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324919.html
上一篇:無法將PHP值轉換為日期型別。應為以下型別之一:null、DateTime
下一篇:禁止用PHP發推?
