primary keyを複数持ちたいです。
現在、usersテーブルに
$table->increments('id');
主キー'id’あり、子テーブルに外部キーとして使用されています
実現したいこと
userテーブルに
id
とstatus_id
を主キーとして持ちたいです。
database/migrations/
public function up() { Schema::table('users', function (Blueprint $table) { $table->integer('id')->change(); $table->dropPrimary('users_id_primary'); $table->primary(['id', 'status_id']); }); } public function down() { Schema::table('users', function (Blueprint $table) { $table->dropPrimary(['users_id_primary', 'users_status_id_primary']); $table->primary('id'); $table->increments('id')->change(); }); }
エラー
SQLSTATE[HY000]: General error: 1833 Cannot change column 'id': used in a foreign key constraint
ご教授くださいm()m
回答1件
あなたの回答
tips
プレビュー