Skip to content

When running php artisan migrate the index name can be too long #215

@daivanaktivbo

Description

@daivanaktivbo

If I have a env with webpush.table_name that is long, then the index for $table->morphs('subscribable'); can be too long.

I get this error

  SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'notification_push_subscriptions_subscribable_type_subscribable_id_index' is too long (Connection: aktivbo_survey, SQL: alter table `notification_push_subscriptions` add index `notification_push_subscriptions_subscribable_type_subscribable_id_index`(`subscribable_type`, `subscribable_id`))

A solution to this could be to have the index already defined like so:

        Schema::connection(config('webpush.database_connection'))->create(config('webpush.table_name'), function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->morphs('subscribable', 'short_index_name'); // like so
            $table->string('endpoint', 500)->unique();
            $table->string('public_key')->nullable();
            $table->string('auth_token')->nullable();
            $table->string('content_encoding')->nullable();
            $table->timestamps();
        });

Have a lovely day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions