Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Default database migration isn't compatible with MySQL #122

Closed
hlorofos opened this issue Apr 27, 2022 · 6 comments · Fixed by #128
Closed

Default database migration isn't compatible with MySQL #122

hlorofos opened this issue Apr 27, 2022 · 6 comments · Fixed by #128

Comments

@hlorofos
Copy link

The following migration with default table settings producing MySQL error:

  SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'plan_subscription_schedules_scheduleable_type_scheduleable_id_index' is too long (SQL: alter table `plan_subscription_schedules` add index `plan_subscription_schedules_scheduleable_type_scheduleable_id_index`(`scheduleable_type`, `scheduleable_id`))
        Schema::create(config('subby.tables.plan_subscription_schedules'), function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('subscription_id');
            $table->morphs('scheduleable');
            $table->timestamp('scheduled_at')->nullable();
            $table->timestamp('failed_at')->nullable();
            $table->timestamp('succeeded_at')->nullable();

            $table->unique(['subscription_id', 'scheduleable_type', 'scheduleable_id', 'scheduled_at'], 'unique_plan_subscription_keys');

            $table->foreign('subscription_id', 'plan_subscription_fk')->references('id')->on(config('subby.tables.plan_subscriptions'))->onDelete('cascade')->onUpdate('cascade');
        });

Workaround is to edit default table name in config/shubby.php to a shorter one.

@Rndwiga
Copy link

Rndwiga commented Apr 29, 2022

Thanks for the post. I got stuck on the same issue. Changing "plan_subscription_schedules" to "subscription_schedules" resolved the issue. This was on MariaDB 10.6.7

@bpuig
Copy link
Owner

bpuig commented May 3, 2022

Hello, It has a name to make it shorter "unique_plan_subscription_keys", but maybe mariaDB does not support it.

@bpuig bpuig linked a pull request Jun 7, 2022 that will close this issue
2 tasks
@bpuig bpuig closed this as completed in #128 Jun 7, 2022
@bpuig
Copy link
Owner

bpuig commented Jun 7, 2022

Found that the bug was not the unique index but in $table->morphs('scheduleable');. v7 fixes many migration errors 👍

@aeq-dev
Copy link

aeq-dev commented Jun 7, 2022

Hi @bpuig
Still the same issue here after updating to v7.0
I fixed it by renaming my tables in config as bellow :

'tables' => [
        'plans' => 'plans',
        'plan_combinations' => 'p_combinations',
        'plan_features' => 'p_features',
        'plan_subscriptions' => 'p_subscriptions',
        'plan_subscription_features' => 'p_subscription_features',
        'plan_subscription_schedules' => 'p_subscription_schedules',
        'plan_subscription_usage' => 'p_subscription_usage',
    ],

@bpuig
Copy link
Owner

bpuig commented Jun 7, 2022

Then maybe you should check this: https://laravel.com/docs/9.x/migrations#index-lengths-mysql-mariadb
If that fixes your issue maybe I can add it to the docs.

@aeq-dev
Copy link

aeq-dev commented Jun 7, 2022

@bpuig Yes that's the problem
Just add Schema::defaultStringLength(191);

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants