On install of payments module I got this error:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes: CREATE TABLE {paymentreference} ( `bundle` VARCHAR(255) NOT NULL, `entity_type` VARCHAR(255) NOT NULL, `field_name` VARCHAR(255) NOT NULL, `pid` INT NOT NULL DEFAULT 0, PRIMARY KEY (`pid`), INDEX `instance` (`bundle`, `entity_type`, `field_name`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8; Array ( ) in db_create_table() (line 2688 of /var/www/vhosts/xxx/httpdocs/includes/database/database.inc).

Is it the module or is it a database setting issue on my side?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

j.slemmer’s picture

Title: On install table "paymetnreference" could not be created. » On install table "paymentreference" could not be created.
Xano’s picture

Thanks for reporting this bug! I'm not familiar with this kind of error, but my search efforts lead me to believe that the combination of the three fields used for the index (bundle, entity_type and field_name) causes the index to be too long. If my calculations are correct, and you are using UTF-8, the index length can be up to (255 + 255 + 255) * 4 bytes = 3060 bytes.

The weird thing is that the tests, which require {paymentreference} to be created, pass both locally and on the testbot.

@j.slemmer: Can you try to run the tests on the machine on which you experience this issue, and try to reproduce the problem on another machine?

j.slemmer’s picture

I tried to reproduce locally, which I could not. Seems to be isolated to our server then.

Not to familiar with running tests. If you want to assist with that, more then willing to give that a try.

Xano’s picture

The Getting Started with SimpleTest should do a good job at explaining how to run tests. Let me know if it works for you!

Xano’s picture

Status: Active » Closed (cannot reproduce)

If anyone can provide steps on how to reproduce this issue, please provide them here and reopen the issue.

Alex Bukach’s picture

Priority: Normal » Major
Status: Closed (cannot reproduce) » Needs work

I have the same issue. For my current dev environment there is a single step to reproduce the issue: deploy fresh D7, then execute
drush dl payment
drush en paymentreference

I use MySQL, UTF-8.

Xano’s picture

Can you give us more details about your environment?

Alex Bukach’s picture

I'm not sure what details can be useful for you since I suppose this issue is caused by using utf-8 with MySQL only.

I use Drupal 7.21, php 5.2.13, MySQL server version 5.1.41-gm2, protocol version 10, encoding UTF-8. What other info can I give you?

mt3ch’s picture

I had this problem so don't have the paymentreference table. Now I've tried to update from 1.5 to 1.6 and just get a white screen each time so I'm wondering if it is related to not having this table.

Do you recommend not applying any updates until this problem is resolved?

Xano’s picture

Version: 7.x-1.4 » 8.x-2.x-dev

Now work on 8.x-2.x has started, we'll have to fix the problem in that branch before we can patch 7.x-1.x. As the database schema is identical, and will be for at least a while, we can probably use the same fix for both branches.

phaer’s picture

I am able to reproduce this bug by using MyISAM as my database engine (payment 7.x-1.7). The same code runs fine on InnoDB which is the default for Drupal but it would be nice to be able to use MyISAM for faster tests during development.

Xano’s picture

Title: On install table "paymentreference" could not be created. » Primary key is too long

This depends on #1709960: declare a maximum length for entity and bundle machine names, as there is no standard maximum length for entity type and bundle machine names yet. paymentreference_schema() uses such high values simply to make sure values are never truncated.

Xano’s picture

Title: Primary key is too long » {paymentreference} index is too long
Xano’s picture

Version: 8.x-2.x-dev » 7.x-1.x-dev
Issue summary: View changes

Moving back to 7.x-1.x, because 8.x-2.x no longer has this table.

Does anyone have more information? I'm still not sure how to solve this.

RemovE’s picture

I changed paymentreference.install schema length values. And now working.

      'bundle' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'field_name' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
Xano’s picture

That will work most of the time, but Drupal 7 does not set explicit limits on the lengths of those values, so this breaks with entity types that have a name that's longer than 32 characters.

vibrasphere’s picture

Hi, I just got this error. 6 months no progress?

Xano’s picture

Status: Needs work » Needs review
FileSize
3.57 KB

Let's try this. It shouldn't break backwards compatibility.

Hi, I just got this error. 6 months no progress?

If nobody has any ideas on how to solve this, then no progress can be made ;-)

Xano’s picture

FileSize
3.36 KB

The previous patch contained a copy/paste error.

The last submitted patch, 18: payment_1924796_18.patch, failed testing.

Xano’s picture

Note that this patch will greatly reduce the chances of running into this error, but it will never be able to fully prevent it, because entity type names, bundles, and field names have no maximum lengths. As long as those three together are no longer than 253 charachters, the patch will work.

torotil’s picture

because entity type names, bundles, and field names have no maximum lengths

That's not entirely true. They are implicitly constrained to the column sizes used in the field-module (one of the reasons to create the notion of entities in the first place). In D7 those limits are:

`entity_type` varchar(128)
`bundle` varchar(128)
`field_name` varchar(32)

Sadly those 3 are indeed longer than 253 characters (288 characters).

torotil’s picture

Hm, Why don't we simply use field_instance_config.id as a foreign key? (Whatever happened to primary-keys?)

In field_instance_config entity_type is limited to 32 chars. That means there is no fieldable entity with a longer entity_type. That's why in field_instance_config the index on exactly the same columns works without any issues on MyISAM.

CREATE TABLE `field_config_instance` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'The primary identifier for a field instance',
  `field_id` int(11) NOT NULL COMMENT 'The identifier of the field attached by this instance',
  `field_name` varchar(32) NOT NULL DEFAULT '',
  `entity_type` varchar(32) NOT NULL DEFAULT '',
  `bundle` varchar(128) NOT NULL DEFAULT '',
  `data` longblob NOT NULL,
  `deleted` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `field_name_bundle` (`field_name`,`entity_type`,`bundle`),
  KEY `deleted` (`deleted`)
) ENGINE=MyISAM AUTO_INCREMENT=327 DEFAULT CHARSET=utf8
torotil’s picture

Here is a patch that limits the columns following field_config_instance.

Xano’s picture

Oh, cool! I have seen some lengthy discussions about maximum lengths in core and IIRC this could never be solved in D7 because there was no maximum.

Thanks!

Xano’s picture

I checked and these are the same restrictions as used for the field_config_instance table.

Xano’s picture

Status: Needs review » Fixed

Thanks for all the help!

  • Xano committed 0719709 on 7.x-1.x authored by torotil
    Issue #1924796 by Xano, torotil: {paymentreference} index is too long
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.