lucabecchetti / laravel-mysql-partition

Useful Laravel package to easily work with MySQL Partition
Other
139 stars 23 forks source link

unique constraint Error #8

Open latif-developers-studio opened 2 years ago

latif-developers-studio commented 2 years ago

If I add any unique constraint then

General error: 1503 A UNIQUE INDEX must include all columns in the table's partitioning function

I got this error.

Here is my migration

Schema::create('cp_transactions', function (Blueprint $table) {

        $table->bigInteger('id');

        $table->primary(['id','date']);

        $table->string('trx_id')->index('trx_id')->unique();

        $table->date('date')->index('date')->nullable();

        $table->timestamps();

    });

    Schema::forceAutoIncrement('cp_transactions', 'id');

    Schema::partitionByYearsAndMonths('cp_transactions', 'date', 2019);

Can you please help me to resolve this issue?

sts-ryan-holton commented 11 months ago

Same error

workOfDsYasir commented 11 months ago

getting same error by implementing unique check on any db column

latif-developers-studio commented 11 months ago

Same error

@sts-ryan-holton, @workOfDsYasir

Yes, there is a constraint by MySQL end. If you are going to apply a database partition then you are unable to add the unique index.

sts-ryan-holton commented 11 months ago

How did you resolve it? It seems the docs: $table->primary(['id','date']); doesn't work

workOfDsYasir commented 11 months ago

How did you resolve it? It seems the docs: $table->primary(['id','date']); doesn't work

You have to create composite key rather than primary key and to create composite key $table->primary(['id','date']); this is the way.

Laravel 10: composite key

sts-ryan-holton commented 11 months ago

This isn't working lol/