mercredi 19 janvier 2022

Laravel - SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined

I'm trying to migrate databases, but my migration is failing on user_info table.

up function

   public function up()
    {
        Schema::table('user_info', function (Blueprint $table) {
            $table->dropColumn('id');
            $table->string('device_name')->nullable()->comment('device name like huawei mate 10 lite');
            $table->text('app_id')->comment('android package name or iOS bundle id');
            $table->string('platform')->nullable()->comment('Android or iOS');
            $table->string('platform_version')->nullable()->comment('Android api version or iOS version');
            $table->string('version_name')->nullable()->comment('Android version name or iOS BundleString');
            $table->integer('version_code')->nullable()->unsigned()->comment('Android version code or iOS BundleVersion');
            $table->string('token_id')->comment('user oauth_access_tokens table id');
            $table->primary(['user_id', 'token_id']);

            $table->foreign('token_id')->references('id')->on('oauth_access_tokens')->onDelete('cascade');
        });
    }

down function

  public function down()
    {
        Schema::table('user_info', function (Blueprint $table) {
            $table->dropPrimary('user_id');
            $table->dropPrimary('token_id');
            $table->dropColumn('device_name');
            $table->dropColumn('app_id');
            $table->dropColumn('platform');
            $table->dropColumn('platform_version');
            $table->dropColumn('version_name');
            $table->dropColumn('version_code');
            $table->dropColumn('token_id');
            $table->bigIncrements('id');
        });
    }

and receive this error:

   Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table `user_info` add `id` bigint unsigned not null auto_increment primary key)

What changes do you think I should make to these codes to fix the problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire