Default database migration isn't compatible with MySQL
Closed this issue ยท 6 comments
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.
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
Hello, It has a name to make it shorter "unique_plan_subscription_keys", but maybe mariaDB does not support it.
Found that the bug was not the unique index but in $table->morphs('scheduleable');
. v7 fixes many migration errors ๐
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',
],
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.