This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ProvidePerfect
ProvidePerfect

I am trying to create a pivot table with the rainlab builder plugin for a $belongsToMany relation of a company id to a category id but getting following error and have found no solution for it yet

SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'namespaceauthor_directory_company_category_pivot_company_id_category_id_primary' is too long (SQL: alter table `namespaceauthor_directory_company_category_pivot` add primary key `namespaceauthor_directory_company_category_pivot_company_id_category_id_primary`(`company_id`, `category_id`))
public function up()
{
    Schema::create('namespaceauthor_directory_company_category_pivot', function($table)
    {
        $table->engine = 'InnoDB';
        $table->integer('company_id');
        $table->integer('category_id');
        $table->primary(['company_id','category_id']);
    });
}

public function down()
{
    Schema::dropIfExists('namespaceauthor_directory_company_category_pivot');
}

Thank you in advance for any help

Yakedo
Yakedo

Hi, I'm sorry to post on such an old topic, but I thought my answer could be useful for others who might stumble accross this issue :

The cause of your issue lies in th Builder plugin, which is not configured to set custom names to compound indexes, and will simply generate a concatenation of the table names and columns. Basically, if you don't specify an index name manually, you will end up with an incredibly long one, which will exceed the character size limit.

I you can't change your table's name, I would advise you not to use the Builder plugin and just create your own migration for this one, but don't forget to specify the index name as the second argument of your primary() index, as mentionned in the October CMS documentation.

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.